WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

For Loop Issue - Need Help

 

winter8
Forum-Newbie

Forum-Newbie


Beiträge: 4
Anmeldedatum: 04.02.18
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 14.01.2020, 11:17     Titel: For Loop Issue - Need Help
  Antworten mit Zitat      
I am trying to do a very simple FOR loop command, but having some problem

What I want is - for example -

x = has gane of values
dx = 0.1

y = x + dx

z = y + xy

The way I want is, x has a range of values, say 1:0.1:2; I like take the first value, which is 1 and plug it in y-equation, i.e. y = 1+0.1= 1.1, then take the value 1.1 and plug it again in y-equation, and get y-value, and insert it again in the y-equation. I like to run this til the end valu of x. i.e 2

However, when value of y=1.1, it will automatic calculate z, and then, when y=1.2, it will plug in to z-equation automatic.

When first value of z is calucated it will go back and take next 2nd value of x=1.1, and calulate y, then z. The loop will continue and will not take random value of x, it will take 1st value, the 2nd valu, then 3rd value of x, and calculate all y and z .

Hope someone can tell me how to do it.

Thanks.
Private Nachricht senden Benutzer-Profile anzeigen


lovobo
Forum-Fortgeschrittener

Forum-Fortgeschrittener


Beiträge: 50
Anmeldedatum: 26.07.15
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 22.01.2020, 07:56     Titel:
  Antworten mit Zitat      
i think most will have a Problem to understand your case here, as i do myself.

however, if i understood it Right, you want to first run the loop only with the first equation, and after it is done, with the 2nd (?)

in that case, just make 2 loops, tho i dont see the Benefit here.
Private Nachricht senden Benutzer-Profile anzeigen
 
winter8
Themenstarter

Forum-Newbie

Forum-Newbie


Beiträge: 4
Anmeldedatum: 04.02.18
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 25.02.2020, 03:31     Titel:
  Antworten mit Zitat      
lovobo hat Folgendes geschrieben:
i think most will have a Problem to understand your case here, as i do myself.

however, if i understood it Right, you want to first run the loop only with the first equation, and after it is done, with the 2nd (?)

in that case, just make 2 loops, tho i dont see the Benefit here.


I have used FOR loop, however, it always pick up random values from "x".

For example, I want x=1.1, then x=1.2, then x=1.3 ...til x=2

The code I tried :

x_range = 1:0.1:2;
x = x_range(randi(numel(x_range)));

The code above is wrong, as it always pick up ranrom values.

I want it should pick up values in sequence.

Can anyone advice me what to do?
Private Nachricht senden Benutzer-Profile anzeigen
 
lovobo
Forum-Fortgeschrittener

Forum-Fortgeschrittener


Beiträge: 50
Anmeldedatum: 26.07.15
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 26.02.2020, 09:19     Titel:
  Antworten mit Zitat      
can you paste your entire code in here and using the code button, so the readability is better.

i may think whats going on here, but i am not 100% sure.

i may completly dont understand hat u wanna achieve here, but the example you showed ... is done by simple

Code:
x = 1:0.1:2;


i dont see the point of using randi, when you dont want to have randomness.
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.