Running a script that produces a value more than once then storing the value each time into a vector
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Maimuna Mohamud
am 3 Feb. 2020
Kommentiert: Maimuna Mohamud
am 4 Feb. 2020
Hi,
I have a script and one of the things it does is calculate and display a certain value. I would like to run this script 10 times and store the value calculated each time in a vector (so the desired end result would be a 1 by 10 vector of 10 values). I've tried to use the 'for loop' function but I don't really understand too well how to apply it and the ways I've tried have caused the code to run indefintely whilst overwriting the previously calculated value each time. I would really appreciate some help,
Thankyou in advance.
1 Kommentar
Mohammad Sami
am 4 Feb. 2020
If you are new to Matlab,I would recommend completing the Matlab OnRamp tutorial. https://matlabacademy.mathworks.com/
Akzeptierte Antwort
Hiro Yoshino
am 4 Feb. 2020
I agree with Mohammad.
Here's the idea:
dataStoringVector = zeros(1,10); % Initialization
for i = 1:10
calcResult = i + 3; % example
dataStoringVector(i) = calResult; % store calculation result in the vector
end
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!