The following code must be written in matlab.
I have a list of inidices say L = [1,2,5,10,6,7,]
I want to loop through indices in a for loop from i=1:n , n=100 but I must skip all indices that are not in the list L
How can I do this if I am not allowed to use the ismember function.
Thankse
MATLAB Code:
% MATLAB Script that skips the indices that are not in the list
clc;
clear;
% List that hold the indices
L = [1,2,5,10,6,7,];
% Assigning n value
n = 100;
% loop through indices in a for loop from i=1:n , n=100
for i=1:n
% Checking indices
% Skipping indices
if (any(L(:)==i) == 1)
% Printing valid indices
fprintf("%d\n", i);
end % If end
end % for end
________________________________________________________________________________________
Sample Run:
Get Answers For Free
Most questions answered within 1 hours.