How to save different files in for loop

3 ビュー (過去 30 日間)
Jiwoo Seo
Jiwoo Seo 2020 年 9 月 27 日
コメント済み: Jiwoo Seo 2020 年 9 月 27 日
Hi,
I'm trying to create separate folders each with a .mat file with temperature data in them (from Feb01 to Apr30). The folders should be like so:
ex) Feb01 folder > Feb01.mat (this .mat file should have 24 temperature data values in them)
But when I run my code I get an error message that says:
Error using save
Must be a text scalar.
Error in Copy_of_testingdates (line 46)
save(FileName,'DataAdj')
Here is my code:
%calibration data
run('HoboConstants.m')
%read data from Feb01 to Apr30
HoboData_C=readmatrix('AB1_Jan22_to_May3.csv','Range','B234:C2393');
HoboData=HoboData_C(:,2)+273.15;
%set month and date vectors
month={'Feb','Mar','Apr'}; %had to attach them bc k reads one alphabet as one column
max_date=[28 31 30];
FileName1={};
DataAdj=[];
FullHoboAdj=[];
%set constants
k=1;
q=1;
m=1;
%saving separate files as ex)"Feb22"
for i=1:24:2136 %decreased 2160 by 24 so that loop runs 89 times
%calibrate data
DataAdj=HoboData(i:(i+23),1)-hoboAB1;
%gives the full calibrated data from Feb01 to Apr30
FullHoboAdj=[FullHoboAdj;DataAdj];
if q>max_date(m)
q=1;
if m<=length(max_date)
m=m+1;
end
if k<=length(month)
k=k+1;
end
end
%creating FileName
z=length(FileName1);
%this will name FileName1 as 'Jan01' up to 'Apr29'
FileName1{z+1}=sprintf('%s%02d',month{k},q);
%flipping the horizontal FileName1 to be vertical
FileName=reshape(FileName1',{},1);
q=q+1;
save(FileName,'DataAdj') %#####This is where the error is#####
end
Thank you!

採用された回答

Walter Roberson
Walter Roberson 2020 年 9 月 27 日
FileName = FileName1{z+1};
  1 件のコメント
Jiwoo Seo
Jiwoo Seo 2020 年 9 月 27 日
Thank you SO MUCH!! I can't believe this simple code solved everything!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by