Question

The following code must be written in matlab. I have a list of inidices say L...

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

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The following code must be written in Matlab I want to print the following in Matlab...
The following code must be written in Matlab I want to print the following in Matlab (x1,x2, x3, ....xn) = (0.33333, 0.33333, 0.33333,....) That is for n variables . The whole thing should be on the same line. I need to use fprintf and write out the coordinates with 5 decimal places of variable xn = (0.33333, 0.33333, 0.33333,....) Thanks!
I have already written a MATLAB code to filter noise from a particular audio file however...
I have already written a MATLAB code to filter noise from a particular audio file however the resulted audio is not playing I use this code snippet: presult = audioplayer(fOut, fs); presult.play; the fout is fOut = filter(b, a, f); I do not know what i am doing wrong as the output playing is still the initial sound not thr noise filtered one. Please help deadline is due in hours. Thanks in advance
The following code must be written in matlab How to convert a 4d unit8 matrix of...
The following code must be written in matlab How to convert a 4d unit8 matrix of size 28 28 1 50000 in Matlab to a matrix of size 784*5000 Give an example that clearly solves this issue. Thanks
MATLAB PROGRAM: (Conditional if and switch).  You must prepare the code (instructions) in Matlab for the following...
MATLAB PROGRAM: (Conditional if and switch).  You must prepare the code (instructions) in Matlab for the following problem. A person weighs 72 kg and wants to know how many calories he spends during the time he performs the same activity. The activities that you are allowed to do are just sleeping or sitting at rest. The data he has are: a) while sleeping he consumes 1.06 calories per minute and b) while sitting at rest he consumes 1.68 calories per minute....
how to modify code in matlab to have a calculation linked to various names? for example...
how to modify code in matlab to have a calculation linked to various names? for example if katie weighs 120 lbs and her density is 2.2, but abby weighs 140 lbs and her density is 3.4 the output i want is volume how do i associate weight and density to a name? so if the user were to input “katie” matlab would know that the weight and density are 120 and 2.2
Write a script (must be titled “NumIntF”) in MATLAB that calculates the integration of function f(x)=cos(x)...
Write a script (must be titled “NumIntF”) in MATLAB that calculates the integration of function f(x)=cos(x) . exp(sin x), Using numerical integration method. When the user runs the script, he/she is prompted to input the lower and upper limits for numerical integration, both in radians, and your program outputs the integration result. You can use built-in trigonometric functions and the exponential function, but you are not allowed to use any built-in function to do the integration. You must use a...
I'm working with doubly linked lists in c++, I have written my classes and constructors. I...
I'm working with doubly linked lists in c++, I have written my classes and constructors. I need help with a randomizing method, any guidance or sample code would be appreciated, I'm pretty lost. For the method: void DLL::Random(); I want to basically shuffle/randomize my list. My list is a list of strings (names) if that's important to know. I'm mainly struggling with how to use pointers to prev and next to apply to each node and then move them throughout...
Microsoft Visual Studio in C#: I have this code and need to loop through each element...
Microsoft Visual Studio in C#: I have this code and need to loop through each element of the patient's array and add to a listbox (lbAccountDisplay) each property of the patient's object. This is the 2nd time to ask this question; it should have all the detail you need to help me. It is a piece of a project and I am trying not to give you the whole project. How do I use a foreach loop to loop through...
Below is the problem that I have and here is the code that I have in...
Below is the problem that I have and here is the code that I have in c++. Can someone help me on what I am doing wrong or the correct code. A teacher has asked all her students to line up according to their first name. For example, in one class Amy will be at the front of the line, and Yolanda will be at the end. Write a program that prompts the user to enter the number of students...
MATLAB save output as array this is my code so far, I'm going to need to...
MATLAB save output as array this is my code so far, I'm going to need to save these as arrays or vectors i think to take some statistics on them. how do i save each walkers position relitive to time I should end up with 1000x 1000 matrix i think or 1000 arrays walkers=1000; %walkers=input('how many walkers do you want to simulate?') N = 1000; %N = input('how many steps do you want?') for k= 1:walkers displacement= randn(1,N); x =...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT