필터 지우기
필터 지우기

Using 'OR' or 'ELSEIF' with a string

조회 수: 2 (최근 30일)
JB
JB 2016년 1월 3일
편집: Image Analyst 2016년 1월 3일
Hi, I have a basic question. I am reading a file named as Basefilename="Filenameversion1.production_time.improvement_date.time_frame.hdf".
The code is not reading files from a folder containing different versions i.e "Filenameversion2......hdf", "Filenameversion3......hdf".
Code only reads filename mentioned in Basefilename.The remaining filename is same only version name is changed.
How can i do modification so that matlab reads file even if 'version' is changed.
Thanks alot

답변 (2개)

Image Analyst
Image Analyst 2016년 1월 3일
The answer for this, along with lots of other good stuff, is in the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F

Star Strider
Star Strider 2016년 1월 3일
I am not certain that I understand what you want to do, but this may be one approach:
ver_nr = 2;
Basefilename=sprintf('Filenameversion%d.production_time.improvement_date.time_frame.hdf', ver_nr)
produces:
Basefilename = Filenameversion2.production_time.improvement_date.time_frame.hdf
Is that what you want to do?
  댓글 수: 10
Star Strider
Star Strider 2016년 1월 3일
I still don’t understand, but if you want to do comparisons with string variables, use strcmpi, strncmpi, or related functions (links to those in and at the end of those pages).
Image Analyst
Image Analyst 2016년 1월 3일
편집: Image Analyst 2016년 1월 3일
A comparison would have == not =. So I don't know if you're wanting to do
if Basefilename == "Filenameversion1.production_time.improvement_date.time_frame.hdf"
% Some code to do if this is true.
elseif Basefilename == "Filenameversion2.production_time.improvement_date.time_frame.hdf"
% Some code to do if this is true.
end
Or if you're trying to do
if num1 == num2
% Assign Basefilename
Basefilename = "Filenameversion1.production_time.improvement_date.time_frame.hdf"
else
% Assign Basefilename
Basefilename = "Filenameversion2.production_time.improvement_date.time_frame.hdf"
end
Which is it? Or is it neither?

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

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by