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

1 view (last 30 days)
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
if isempty( )
  1 Comment
Stephen23 on 19 Mar 2023
Edited: Stephen23 on 20 Mar 2023
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;

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 17 Mar 2023
Edited: John D'Errico on 17 Mar 2023
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?
John D'Errico
John D'Errico on 19 Mar 2023
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...
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.

Sign in to comment.

More Answers (0)


Find more on Install Products in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by