Effacer les filtres
Effacer les filtres

Save while loop data?

19 vues (au cours des 30 derniers jours)
Katerina Tetzloff
Katerina Tetzloff le 23 Oct 2015
Commenté : Mouli le 12 Juin 2023
If I have a while loop that records certain data points, I know how to fprintf in each time the loop goes around, but how can I save these to a matrix without the values getting replaced each time? The loop records the (x,y) coordinates of the cursor every time I click the mouse, and I want to export this into a matrix with all the x values and with all the y values if possible.
Thank you!

Réponse acceptée

Mohammad Abouali
Mohammad Abouali le 23 Oct 2015
Modifié(e) : Mohammad Abouali le 23 Oct 2015
You can do it like this:
% first initialize myCoordList to an empty matrix
myCoordList=[];
while (some condition)
% some code that get's your x and y code
myCoordList=[myCoordList; [x, y]];
end
This way as you get more x and y pairs another row is added to myCoordList.
instead of using
myCoordList=[myCoordList; [x, y]];
you can also use:
myCoordList(end+1,:)=[x, y];
(Just use one of them not both)
  8 commentaires
Cholisina
Cholisina le 8 Mar 2023
I really happy to found this, thanks a lot
Mouli
Mouli le 12 Juin 2023
I have no words, how to thank you. God bless you. I was trying my code for hours and value was getting reset everytime. Thanks a lot.

Connectez-vous pour commenter.

Plus de réponses (1)

shipakane ndhlovu
shipakane ndhlovu le 29 Nov 2022

Can someone please explain to me, what is really happening I see the coding working with just using that but what does it mean

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by