I'd like to skip the file that's not there and bring it up!

조회 수: 1 (최근 30일)
KRLKL
KRLKL 2023년 3월 17일
편집: Stephen23 2023년 3월 20일
Hello, I am a student who is learning mat rap. I left a question because I didn't know something while doing the assignment.
The codes I have to sing are NO_001, NO_002,...Code up to NO_100.
There is a missing number among the 100 numbers.
I want to keep the for statement except for this missing file, but I don't know what function to put in it.
clc; clear;
for k=1:100
load(['01__input/NO_',num2str(k,'%03d'),'.mat'],'data')
if isempty( )
continue
end
end
  댓글 수: 1
Stephen23
Stephen23 2023년 3월 19일
편집: Stephen23 2023년 3월 20일
A simple alternative approach is to use DIR, then you can simply avoid the problem:
S = dir('01__input/NO_*.mat');:
for k = 1:numel(S)
F = fullfile(S(k).folder,S(k).name);
D = load(F,'data');
.. do whatever with D.data, or store for later processing:
S(k).data = D.data;
end

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

채택된 답변

John D'Errico
John D'Errico 2023년 3월 17일
편집: John D'Errico 2023년 3월 17일
mat rap? Is that some godawful new song I've never heard before? ;-) That just seems, well, raprehensible to me.
You don't want to use isempty there. Instead, use the exist function. Test to see if the file exists, BEFORE you try to load the file. If it does not exist, then do you want to try load it in the first place?
  댓글 수: 2
KRLKL
KRLKL 2023년 3월 19일
Oh my! I didn't know I wrote "mat rap" wrong! You pointed it out tactfully! Thanks to you, I completed the assignment using 'exist'. Thank you so much! Always be happy!
John D'Errico
John D'Errico 2023년 3월 19일
Why is it every older generation never seems to undertand the music of today, regardless of what generation we are in? Let me ask MATLAB...
why
It should be obvious.
Gosh, I'm not sure that explains anything. Darn computers.
Anyway, I had to laugh a little. But MATLAB does not understand rap either. For example,
help rapmat
--- rapmat not found. Showing help for repmat instead. --- REPMAT Replicate and tile an array. B = REPMAT(A,M,N) or B = REPMAT(A,[M,N]) creates a large matrix B consisting of an M-by-N tiling of copies of A. If A is a matrix, the size of B is [size(A,1)*M, size(A,2)*N]. B = REPMAT(A,N) creates an N-by-N tiling. B = REPMAT(A,P1,P2,...,Pn) or B = REPMAT(A,[P1,P2,...,Pn]) tiles the array A to produce an n-dimensional array B composed of copies of A. The size of B is [size(A,1)*P1, size(A,2)*P2, ..., size(A,n)*Pn]. If A is m-dimensional with m > n, an m-dimensional array B is returned. In this case, the size of B is [size(A,1)*P1, size(A,2)*P2, ..., size(A,n)*Pn, size(A, n+1), ..., size(A, m)]. REPMAT(A,M,N) when A is a scalar is commonly used to produce an M-by-N matrix filled with A's value and having A's CLASS. For certain values, you may achieve the same results using other functions. Namely, REPMAT(NAN,M,N) is the same as NAN(M,N) REPMAT(SINGLE(INF),M,N) is the same as INF(M,N,'single') REPMAT(INT8(0),M,N) is the same as ZEROS(M,N,'int8') REPMAT(UINT32(1),M,N) is the same as ONES(M,N,'uint32') REPMAT(EPS,M,N) is the same as EPS(ONES(M,N)) Example: repmat(magic(2), 2, 3) repmat(uint8(5), 2, 3) Class support for input A: float: double, single integer: uint8, int8, uint16, int16, uint32, int32, uint64, int64 char, logical See also BSXFUN, MESHGRID, ONES, ZEROS, NAN, INF. Documentation for repmat doc repmat Other uses of repmat codistributed/repmat gpuArray/repmat symfun/repmat embedded.fi/repmat InputOutputModel/repmat tall/repmat
It does try. But it gets confused. :)
Anyway, have a nice day. I'm happy to have made you smile.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by