フィルターのクリア

how to save 3 files in one script?

1 回表示 (過去 30 日間)
Liyun
Liyun 2014 年 3 月 9 日
コメント済み: Image Analyst 2014 年 3 月 9 日
I want to derive 3 subsets of data using one input data, but I am don't know how to save them to 3 files. There must be something wrong with the syntax? What is the correct syntax of saving files?
Thank you so much
function [data2,data3,data4]=clean_data(file)
load(file);
jj=1;
for ii=1:length(data)
if(~isnan(data(ii,2)))
data2(jj,:)=data(ii,:);
jj=jj+1;
end
end
ll=1;
for kk=1:length(data2)
if(data2(kk,2)==1)
data3(ll,:)=data2(kk,:)
ll=ll+1;
end
end
mm=1;
for kk=1:length(data2)
if(data2(kk,2)==0)
data4(mm,:)=data2(kk,:)
mm=mm+1;
end
end
save('clean_data','newdataC','newdataE')
end

採用された回答

the cyclist
the cyclist 2014 年 3 月 9 日
It is not clear to me what you want to do. I am guessing that you want to
  • Save data2 to the file 'clean_data.mat'
  • Save data3 to the file 'newdataC.mat'
  • Save data4 to the file 'newdataE.mat'
If that is correct, here is how to do that:
save('clean_data','data2')
save('newdataC','data3')
save('newdataE','data4')
  3 件のコメント
the cyclist
the cyclist 2014 年 3 月 9 日
In the save() command, the first input is the filename, and the rest are the variables that will be saved to that file. You can only save to one file at a time.
In my syntax, I save the variable data2 to the file clean_data, then data3 to file newdataC, etc.
In your syntax, you are telling MATLAB to save the variables named newdataC and newdataE to the file named clean_data.
You get an error with your syntax because there is no variable named newdataC.
Image Analyst
Image Analyst 2014 年 3 月 9 日
I think it would be more explicit to say
save('clean_data.mat','data2')
save('newdataC.mat','data3')
save('newdataE.mat','data4')
which would make it clear that the first arg is a filename, not just some variable.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by