How to save different files in for loop
3 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!