2017-08-13 4 views
0

私は毎日データを解析しているmatlabアプリケーションを作成しています。完全な情報を提供しないことについて申し訳ありません データは関数xlsreadを使用してCSVファイルから読み込んだ()Matlabは変数名を持つ.matファイルを保存します

[num, weather, raw]=xlsread('weather.xlsx'); 
% weather.xlsx is a spreadsheet that holds a list of other files (csv) i 
% want to process 
for i = 1:length(weather) 
    fn = [char(weather(i)) '.csv']; 

    % now read in the weather file, get data from the local weather files 
    fnOpen = xlsread(fn); 

    % now process the file to save out the .mat file with the location name 
    % for example, one file is dallasTX, so I would like that file to be 
    % saved as dallasTx.mat 
    % the next is denverCO, and so denverCO.mat, and so on. 
    % but if I try... 
    fnSave=[char(weather(i)) '.mat'] ; 
    save(fnSave, fnOpen) % this doesn't work 

    % I will be doing quite a bit of processing of the data in another 
    % application that will open each individual .mat file 
end 

++++++++++++++ 。 上記のときにエラーが発生します。 保存時にエラーが発生しました 引数には文字列を含める必要があります。

XiangruとWolfieは、あなたが提案したようにsave(fnSave、 'fnOpen')を動作させます。今私はdallasTX.matファイルを持っていて、変数名はfnOpenです。私は今これで作業することができます。

お返事ありがとうございます。

答えて

1

動作しないときにエラーメッセージを表示すると便利です。

この場合、問題はの保存の構文だと思います。

save(fnSave, 'fnOpen'); % note the quotes 

また、char(weather(i))の代わりにweather {i}を使用することもできます。 documentationから、

0

save(filename, variables) 

variablesを説明する必要があるように、コマンド使用:保存する変数の

名、一つ以上の文字ベクトルや文字列として指定します。 saveのコマンド・フォームを使用する場合は、入力を一重引用符または二重引用符で囲む必要はありません。変数は次のいずれかの形式になります。

これは、あなたがまた、変数に格納されたファイル名を使用したいので、あなたがevalを使用する必要があるだろうとして、コマンドの構文は理想的ではありません

save(fnSave, 'fnOpen'); 

を使用する必要がありますを意味します。あなたは(今後の参考のために)固定されたファイル名を持っていた場合この場合の代替オプションが

eval(['save ', fnSave, ' fnOpen']); 

だろう、これは単純になり

save C:/User/Docs/MyFile.mat fnOpen 
関連する問題