フィルターのクリア

save a for loop

1 回表示 (過去 30 日間)
Fateme Jalali
Fateme Jalali 2015 年 12 月 9 日
回答済み: Fateme Jalali 2015 年 12 月 10 日
Hi,I want to save all outputs of for loop (all s) in this program.my data set is:' i want to do my thesis as well as possible ' can any one help me ?
text1 = fileread('D:/a.txt');
length1=length(text1);
whitespace1 = find(text1,' ');
w=strfind(text1,' ');
u=1:size(w,2);
%s=zeros(size(w,2)-1,2)
for i=1:size(w,2)-1;
s = text1(w(i)+1:w(i+1)-1)
end

採用された回答

goerk
goerk 2015 年 12 月 10 日
If you want to use a for-loop you can use this adaption of your code:
text1 = ' i want to do my thesis as well as possible ';
w=strfind(text1,' ');
s=cell(size(w,2)-1,1)
for i=1:size(w,2)-1;
s{i} = text1(w(i)+1:w(i+1)-1);
end
It is also possible to use the string split command:
text1 = ' i want to do my thesis as well as possible ';
s = strsplit(text1,' ');
% to get the same result as above: remove the empty cells (at the beginning and the end)
% and transpose the cellarray
s(cellfun(@isempty,s))' = [];

その他の回答 (1 件)

Fateme Jalali
Fateme Jalali 2015 年 12 月 10 日
thank you so much. best wishes for you

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by