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
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...
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...
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 =...
I am having some trouble writing some java code involving strings. I have included the code...
I am having some trouble writing some java code involving strings. I have included the code provided by my professor below. that has the instructions in it as well public class StringExercise { public static void main(String[] args) { String given = "The quick brown fox jumped over the moon!"; String given2 = "mary"; String given3 = "D"; //Write a Java code snippet to check (print a boolean) whether the given String ends with the contents of "oon!", see endsWith...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class and a Node class (please name your classes exactly ​as I did here). Please follow the below specifications for the two classes. Node.cpp ● This must be a generic class. ● Should contain a generic member variable that holds the nodes value. ● Should contain a next and prev Node* as denoted here. ● All member variables should be private. ● Use public and...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions...
It is about C++linked list code. my assignment is making 1 function, in below circumstance,(some functions are suggested for easier procedure of making function.) void search_node(struct linked_list* list, int find_node_ value) (The function to make) This function finds the node from the list that value is same with find_node_value and count the order of the node. This function should print message “The order of (node_value) is (order).” and error message “Function search_node : There is no such node to search.”....
I have the following RStudio code which works match_prob <- function(x) choose(2*N-x,N)*2 ̂ {-(2*N-x)} It corresponds...
I have the following RStudio code which works match_prob <- function(x) choose(2*N-x,N)*2 ̂ {-(2*N-x)} It corresponds to P(E) = (2N-k,N)(1/2)^(2N-k) I however want to use a slightly different function. Is it possible to input for the following: P(E) = 2(2N-k,N)(1/2)^(2N-k) I tried entering it in by changing the function slightly to: match_prob <- function(x) choose(2*(2*N-x,N))*2 ̂ {-(2*N-x)} and immediately got the error, "Error: unexpected ',' in "match_prob"... The change was a factor of 2 since the container which are considered...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT