MATLAB Answers

How do I store output from double for loops, I only get the last iteration?

2 ビュー (過去 30 日間)
Linus Dock
Linus Dock 2016 年 10 月 6 日
コメント済み: Linus Dock 2016 年 10 月 6 日
Hi, I have forgot how to store my output from the following for loop. I only recover the last iteration of my outer for loop but I would like to store all the data in either one long cell or one cell for each iteration. Is it possible to this and in that case could someone please help? The output cell is flygplatsmetar.
Thank you!
for l = 1:length(Data);
s = strfind(Data{l},a);
empty=zeros(1,length(Data{l}))';
j=0;
for k = 1:length(Data{l})
ind = find(s{k});
if ind==1;
empty(k)=j+1;
end
end
metar = find(empty);
Nydata = Data{l};
flygplatsmetar = Nydata(metar);
end

  0 件のコメント

Sign in to comment.

採用された回答

KSSV
KSSV 2016 年 10 月 6 日
flygplatsmetar = cells(length(Data),1) ;
for l = 1:length(Data);
s = strfind(Data{l},a);
empty=zeros(1,length(Data{l}))';
j=0;
for k = 1:length(Data{l})
ind = find(s{k});
if ind==1;
empty(k)=j+1;
end
end
metar = find(empty);
Nydata = Data{l};
flygplatsmetar{l} = Nydata(metar);
end

  2 件のコメント

Linus Dock
Linus Dock 2016 年 10 月 6 日
Thanks a lot!
elias GR
elias GR 2016 年 10 月 6 日
The commend is 'cell', not 'cells'...

Sign in to comment.

その他の回答 (1 件)

elias GR
elias GR 2016 年 10 月 6 日
flygplatsmetar = cell(1,length(Data)); %initialize your 1D cell array
for l = 1:length(Data)
...
flygplatsmetar{l} = Nydata(metar); %store the data
end

  1 件のコメント

Linus Dock
Linus Dock 2016 年 10 月 6 日
Hi! I have Another question: How can I merge these cells from
<1x6 cell>
into one long cell. I can't get it to work iteratively inside the for loop. The manual code I'm trying to replicate is:
flygplatsmetar=[Utcell{1};Utcell{2};Utcell{3}]
Here Utcell is my Output from the for-loop instead and flygplatsmetar is the long cell I'm trying to constuct. Thank you for your reply!

Sign in to comment.


Translated by