From: dpb on
roya olyazadeh wrote:
>
....
> I read your comments tnx. But I am not professional in MATLAB. I use
> this : tline = fgetl(fid);
> answer = findstr(tline,'END OF HEADER');
> if ~ischar(tline), break, end
> to display my text after reading.

I don't follow, but ok...

> case A and D must be in separate array because I need to do computation
> separately.

But then you'll need some other place to store them besides the same
array names used previously.

> and after running I have d and a and c Are a and c and d matrix? Why
> couldn't I use them like this?? degree=a(1,4) 'degree' is empty.
> I tried to use textscan but where? D = textscan(d,'%d %d %f %f
> %*[^\n]'); d is array from strvcat
....

OK, this parses the two cases you gave answers for -- it's kinda' klunky
because there isn't a convenient way to concatenate multiple arrays in a
single statement and assuming the arrays aren't terribly huge and you
don't have to do this a whole bunch of times I didn't preallocate arrays
and index not having an a priori count of maximum size.

x = []; a = x; b = x; d = x; % create some empty arrays
while ~feof(fid)
s=fgetl(fid); % get a line
if isempty(s), continue, end % skip any empty lines
switch upper(s(1)) % make it upper for single test
case {'C'}
x = [x; sscanf(s(2:end), '%*d%f%f)')'];
case ('A')
% don't have a rule for this case...
case ('D')
% read into temporary variable then concat into arrays...
[r,s,t] = strread(s(2:end),'%d%d%f%*[^\n]')
a = [a;r]; b = [b;s]; d = [d;t]
otherwise
disp(['Unknown case: ' s(1)])
end
end

I don't have a late enough version to debug us' anonymous functions
version -- it'll undoubtedly be somewhat cleaner if you do.

As for "being professional", it's "time in grade" -- if you're going to
use Matlab, spend some time reading the "Getting Started" section. It
will pay off in the longer run if your project is anything more than a
day long effort...

--
From: roya olyazadeh on

> OK, this parses the two cases you gave answers for -- it's kinda' klunky
> because there isn't a convenient way to concatenate multiple arrays in a
> single statement and assuming the arrays aren't terribly huge and you
> don't have to do this a whole bunch of times I didn't preallocate arrays
> and index not having an a priori count of maximum size.
>
> x = []; a = x; b = x; d = x; % create some empty arrays
> while ~feof(fid)
> s=fgetl(fid); % get a line
> if isempty(s), continue, end % skip any empty lines
> switch upper(s(1)) % make it upper for single test
> case {'C'}
> x = [x; sscanf(s(2:end), '%*d%f%f)')'];
> case ('A')
> % don't have a rule for this case...
> case ('D')
> % read into temporary variable then concat into arrays...
> [r,s,t] = strread(s(2:end),'%d%d%f%*[^\n]')
> a = [a;r]; b = [b;s]; d = [d;t]
> otherwise
> disp(['Unknown case: ' s(1)])
> end
> end
>
> I don't have a late enough version to debug us' anonymous functions
> version -- it'll undoubtedly be somewhat cleaner if you do.
>
> As for "being professional", it's "time in grade" -- if you're going to
> use Matlab, spend some time reading the "Getting Started" section. It
> will pay off in the longer run if your project is anything more than a
> day long effort...
>
> Now it works. Thank you very much .
Now I am moving to next part of my project. tnx again

clc
filename=input('Input the filename:','s');

fid=fopen(filename);
head_lines = 0;

x = []; at = x; fr = x; tt = x; deg=x;
min=x; sec=x; from=x; to=x; dist=x; var=x; var2=x;
stn=x; y=x; fix1=x; fix2=x;
i=0;j=0;h=0;

while ~feof(fid)
head_lines = head_lines+1;
tline = fgetl(fid);
answer = findstr(tline,'END OF HEADER');
if ~ischar(tline), break, end
disp(tline)

switch tline(1)
case {'C' }
[q,r,s,t,u] = strread(tline(2:end), '%d %f %f %s %s %*[^\n]');
stn=[stn;q]; x=[x;r]; y=[y,s]; fix1=[fix1;t]; fix2=[fix2;u];
i=i+1;

case ('D')
[m, n, o, p] = strread(tline(2:end),'%d %d %f %f %*[^\n]');
from = [from;m]; to = [to;n]; dist = [dist;o]; var = [var;p];
j=j+1;

case ('A')
[a, b, c,d,e,f,g] = strread(tline(2:end),'%d %d %d %f %f %f %f %*[^\n]');
at = [at;a]; fr = [fr;b]; tt = [tt;c];
deg = [deg;d]; min = [min;e];sec = [sec;f];var2 = [var2;g];
h=h+1;

end

end

fclose(fid);
From: dpb on
roya olyazadeh wrote:
>
>> OK, this parses the two cases you gave answers for --
....
>> Now it works. Thank you very much .
> Now I am moving to next part of my project. tnx again
....
> filename=input('Input the filename:','s');
....

doc uigetfile % and friends may be convenient here...

--
From: roya olyazadeh on
dpb <none(a)non.net> wrote in message <hrk0bn$qhp$1(a)news.eternal-september.org>...
> roya olyazadeh wrote:
> >
> >> OK, this parses the two cases you gave answers for --
> ...
> >> Now it works. Thank you very much .
> > Now I am moving to next part of my project. tnx again
> ...
> > filename=input('Input the filename:','s');
> ...
>
> doc uigetfile % and friends may be convenient here...
>
> --


Hi
I have another question.. Can you tell me how can I add string to a matrix.
For this example I have this matrix :

from=[1 ;2 ;4; 6; 7; 8 ]
Now I want to add x to them so I have
from=[x1;x2;x4;x6;x7;x8]

tnx againt for your help.
From: us on
"roya olyazadeh"
> > This error occurred after running
>
> Too many inputs.
>
> Error in ==> secndcor at 13
> v=cellfun(@(x) sscanf(x,tmpl{i,3}),s(ix),'uni',false);
>
> and one thing , file size is changeable. sometimes maybe 100 lines . sometimes they
> are not in order like this :
> D 1 2 122.286 0.002
> A 1 2 5 35 17 32.00 3.0
> C 1 1000.000000 1000.000000 !
> D 1 3 190.522 0.002
> C 4 878.926000 1021.071000 ! !
>
> What is the solution ?

which ML version do you have(?)...
can you upgrade(?)...
note: the order of your character tags does not matter...

us