the output result only saves the last (unusual1.dat) file instead of all three.
if f==1 save Norm.dat stats -ascii %Save data to dat file using ascii
else if f==2 save Unusual.dat stats -ascii
else
save Unusual2.dat stats -ascii
end
end
Could you help me where is my problem, please?

 채택된 답변

Stephen23
Stephen23 2018년 8월 20일
편집: Stephen23 2018년 8월 20일

0 개 추천

The mistake that both you and Image Analyst made is to use command syntax, whereas you need to use function syntax like this:
fnm = sprintf('Unusual%d.dat', f);
save(fnm,'stats','-ascii')
This is clearly explained in the MATLAB help: "When a function input is a variable, you must use function syntax to pass the value to the function."

댓글 수: 1

Image Analyst
Image Analyst 2018년 8월 20일
Good catch. I just used his code for save without thinking.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 8월 19일
편집: Image Analyst 2018년 8월 19일

0 개 추천

I guess then that f never obtains the value of anything other than 1 or 2.
In your loop, construct the file name with sprintf and use that instead of the multiple if block:
filename = sprintf('Unusual%d.dat', f);
save filename stats -ascii

카테고리

도움말 센터File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

태그

질문:

2018년 8월 19일

댓글:

2018년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by