Question

In: Computer Science

Hi I'm trying to use a for loop in Matlab to run over the times inside...

Hi I'm trying to use a for loop in Matlab to run over the times inside a vector. For example N = [10 20 30], the for loop should run the first number of the loop 10 times once and then the same loop again 20 times and so on. So the program must run the loop 3 times but with the different numbers of the vector.

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

% Take the vector
N = [10 2 1]

% Start a for loop
for i=1:length(N)
% each time loop for N[i] number of times
for j=1:N(i)
% Print the j value
disp(j)
end
disp(' ')
end

================

ANOTHER EXAMPLE


Related Solutions

In MATLAB FOR loops: Repeat a block command a certain number of times Use a loop...
In MATLAB FOR loops: Repeat a block command a certain number of times Use a loop index Can use a non-unit stride Are required for any kind of animations An accumulator: MUST start at zero Can be used to keep track of a quantity each time through the loop Can be used to calculate how a sum changes with each loop Should be coded, for loops are more efficient For loops: Perform a set task a set number of times...
I'm having trouble with my do while loop. I'm trying to get it where if the...
I'm having trouble with my do while loop. I'm trying to get it where if the user enter's 3 after whatever amount of caffeinated beverages they've entered before then the loop will close and the rest of my code would proceed to execute and calculate the average price of all the caffeinated beverages entered. Can someone please help me with this? Here's my Code: import java.util.Scanner; public class Main { public static void main(String[] args) { CaffeinatedBeverage[] inventory = new...
I'm trying to get the union of two arrays and I tried making a loop that...
I'm trying to get the union of two arrays and I tried making a loop that does so. I tried also making the loop give me the size of the array as well from the union of the two arrays. Please check my loop to see what is wrong with it because it is not doing what I want it to do. I'm also not sure how to get the correct size of the array after the two arrays have...
Hi: I'm trying to do a lab called " Making solutions with Alkali Halides (And Breaking...
Hi: I'm trying to do a lab called " Making solutions with Alkali Halides (And Breaking Them). The Lab is by John B. Brady. The lab is about X-ray diffraction and I am suppose to answer a few questions and plot the molar composition vs d-values for KCL and NaCl mixture, as well as the d111 for each sample. I have the data but I honestly am comfused about how to stay this lab. Any ideas would be appreciated. Thank...
Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want...
Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want to plot a 3D animated orbit which is a 60 by 58 nautical miles orbit. Can you provide a code or some idea of how to plot an orbit like this in 3D?
I'm trying to get my code to loop back to let the user input multiple patients....
I'm trying to get my code to loop back to let the user input multiple patients. import java.util.Scanner; public class XYZ {    public static void main(String[] args) {           String response;        do{            //import scanner for input            Scanner input = new Scanner(System.in);               //prompt user input for last name            System.out.print("Enter last name ");            //output for last name            String...
Hi, I'm trying to rewrite the code below (code #1) by changing delay() to millis(). void...
Hi, I'm trying to rewrite the code below (code #1) by changing delay() to millis(). void loop() { // Print the value inside of myBPM. Serial.begin(9600); int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int". // "myBPM" hold this BPM value now. if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened". Serial.println("♥ A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened". Serial.print("BPM:...
Hi. I'm trying to write a program that uses dynamic memory management to create two arrays....
Hi. I'm trying to write a program that uses dynamic memory management to create two arrays. splice() must create the third array and return a pointer to main(). Main() must capture the pointer returned from the splice() function. Sol'n so far, I get the results of the first and second array, but it isn't showing the results of the spliced function: #include <iostream> using namespace std; // Function int* splice() inserts the 2nd array into 1st array starting at int...
Hi, I'm trying to make a basic GUI quiz in python using tkinter. I would like...
Hi, I'm trying to make a basic GUI quiz in python using tkinter. I would like the user to have to press a start button to begin the quiz and then be asked 5 different questions with the total score showing at the end. Ideally it would be a multiple choice quiz with the user having 4 different answers to choose from. A very basic example of this would be appreciated so I can understand where exactly I'm going wrong....
I'm trying to use Jupyter (python) to convert the contents of a pkl file into a...
I'm trying to use Jupyter (python) to convert the contents of a pkl file into a dictionary, WITHOUT using pandas. I'm able to import pickle and can open my file...but I'm not sure how to create the dictionary.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT