필터 지우기
필터 지우기

How to save different files in for loop

조회 수: 2 (최근 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 CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by