Accumulating data in a loop while (2024)

8 Ansichten (letzte 30 Tage)

Ältere Kommentare anzeigen

gravy am 29 Jan. 2024

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while

  • Verknüpfen

    Direkter Link zu dieser Frage

    https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while

Kommentiert: gravy am 29 Jan. 2024

Akzeptierte Antwort: Voss

In MATLAB Online öffnen

Good evening, I need to collect data into an array with accumulation.

For example, there are 9 time values t=9, the array should look like this (0 t1 t1+t2 t1+t2+t3 and...) I want to do this in a loop so that it would be possible to regulate the number of t values.

So far I've thought of this, but it doesn't work correctly:

index=1;

n=10;

c=[];

while index<10

t = b(index)+b(index+1)

if t>b(index) && index<10

t1=0;

t1 = t + b(index)

index=index+1;

end

c=[c t1];

end

Unrecognized function or variable 'b'.

c

3 Kommentare

1 älteren Kommentar anzeigen1 älteren Kommentar ausblenden

Dyuman Joshi am 29 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046371

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046371

Few things -

"b" is not defined.

You initialize "t1" as zero, but then over-write in the next line, which does not makes sense to me.

What are you trying to do? What is the objective? What is the code suppose to do?

You have added the tag "database" for this question - How does a database come into this question?

gravy am 29 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046376

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046376

"b" this is part of the previous code

gravy am 29 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046396

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046396

Bearbeitet: Walter Roberson am 29 Jan. 2024

In MATLAB Online öffnen

This is what it looks like in simple form

%t0=0;

%t1=delt0;

%t2=delt0+delt1;

%t3=delt0+delt1+delt2;

%t4=delt0+delt1+delt2+delt3;

%t5=delt0+delt1+delt2+delt3+delt4;

%t6=delt0+delt1+delt2+delt3+delt4+delt5;

%t7=delt0+delt1+delt2+delt3+delt4+delt5+delt6;

%t8=delt0+delt1+delt2+delt3+delt4+delt5+delt6+delt7;

%t9=delt0+delt1+delt2+delt3+delt4+delt5+delt6+delt7+delt8;

%t10=delt0+delt1+delt2+delt3+delt4+delt5+delt6+delt7+delt8+delt9;

%t = [t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10];

I want to automate this process and not write new variables myself every time.

Here is the full code, maybe it will become clearer:

X = linspace(0,100,12);

for x = X

if (0<=x) && (x<5.5)

y1=((x-0)/(5.5-0))*(7.74-9.19)+9.19;

end

if (5.5<=x) && (x<14.5)

y2=((x-5.5)/(14.5-5.5))*(6.45-7.74)+7.74;

end

if (14.5<=x) && (x<22.5)

y3=((x-14.5)/(22.5-14.5))*(5.56-6.45)+6.45;

end

if (22.5<=x) && (x<30)

y4=((x-22.5)/(30-22.5))*(4.79-5.56)+5.56;

end

if (30<=x) && (x<43.5)

y5=((x-30)/(43.5-30))*(3.43-4.79)+4.79;

end

if (43.5<=x) && (x<49)

y6=((x-43.5)/(49-43.5)).*(3.04-3.43)+3.43;

end

if (49<=x) && (x<56)

y7=((x-49)/(56-49))*(2.39-3.04)+3.04;

end

if (56<=x) && (x<64)

y8=((x-56)/(60-56)).*(0.8-2.39)+2.39;

end

if (64<=x) && (x<73)

y9=((x-60)/(70-60))*(-1.98-0.8)+0.8;

end

if (73<=x) && (x<83)

y10=((x-70)/(80-70))*(-3.88+1.98)-1.98;

end

if (83<=x) && (x<93)

y11=((x-80)/(90-80))*(-5.45+3.88)-3.88;

end

if (93<=x) && (x<=100)

y12=((x-90)/(100-90))*(-6.74+5.45)-5.45;

end

end

Y=[y1 y2 y3 y4 y5 y6 y7 y8 y9 y10 y11 y12];

X = linspace(0,100,12);

v = [ 0:10:100 ];

delv=10;

dzeta = 120;

w0=0;

v1=0;

a=[];

while v1<100 %&& w0<3

fycp = abs(((interp1(X,Y,v1)-w0)+((interp1(X,Y,v1+delv))-w0)))/2;

v1=v1+10;

% w0=w0+1;

a=[a fycp];

end

b=[];

index=1;

while index<11

delt = delv/(dzeta*a(index));

index=index+1;

b=[b delt];

end

index=1;

n=10;

c=[];

while index<10

t = b(index)+b(index+1)

if t>b(index) && index<10

t1=0;

t1 = t + b(index)

index=index+1;

end

c=[c t1];

end

Melden Sie sich an, um zu kommentieren.

Melden Sie sich an, um diese Frage zu beantworten.

Akzeptierte Antwort

Voss am 29 Jan. 2024

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#answer_1399241

  • Verknüpfen

    Direkter Link zu dieser Antwort

    https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#answer_1399241

In MATLAB Online öffnen

t = rand(1,9) % 9 random t values

t = 1×9

0.7787 0.5803 0.4362 0.3903 0.0329 0.8313 0.1897 0.7956 0.7963

c = c*msum([0 t]) % c = [0, t(1), t(1)+t(2), t(1)+t(2)+t(3), etc.]

c = 1×10

0 0.7787 1.3590 1.7951 2.1854 2.2183 3.0496 3.2394 4.0349 4.8312

4 Kommentare

2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden

gravy am 29 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046416

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046416

You yourself assigned indices 1,2,3, etc., but I want the program to add the next value to the previous one, and I could regulate the number of “indices” myself.

Voss am 29 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046421

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046421

In MATLAB Online öffnen

It seems like you want to cumulatively sum the t where the next b is positive, based on this:

t = b(index)+b(index+1)

if t>b(index) && index<10

That is, given that t = b(index)+b(index+1), then t>b(index) implies b(index+1)>0.

b = randn(1,10) % 10 random b values, some of which are negative

b = 1×10

-0.7297 -0.1824 0.8041 1.0788 -0.7439 -0.8178 1.7741 0.2454 -1.5478 -1.7278

t = rand(1,9) % 9 random t values

t = 1×9

0.2471 0.7733 0.9757 0.7641 0.3566 0.9937 0.5369 0.1627 0.0781

idx = find(b > 0);

if ~isempty(idx) && idx(1) == 1

idx(1) = [];

end

c = c*msum([0 t(idx-1)]) % cumulatively sum the elements of t where the next b is positive

c = 1×5

0 0.7733 1.7490 2.7427 3.2796

gravy am 29 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046431

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046431

Bearbeitet: gravy am 29 Jan. 2024

still not the same, it should look like you wrote before:

t = rand(1.9) % 9 random t values

c = c*msum([0 t]) % c = [0, t(1), t(1)+t(2), t(1)+t(2)+t(3), etc.]

But the summation in the array should be done automatically, I want to change the value of t, but not rewrite the array every time. There will be a graph with "b" and "c" and their number in the array should converge.

I tried to set some kind of condition, but I couldn’t figure it out yet.

gravy am 29 Jan. 2024

Direkter Link zu diesem Kommentar

https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046446

  • Verknüpfen

    Direkter Link zu diesem Kommentar

    https://de.mathworks.com/matlabcentral/answers/2075881-accumulating-data-in-a-loop-while#comment_3046446

I'm an idiot, your previous answer was correct. Thanks a lot

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Melden Sie sich an, um diese Frage zu beantworten.

Siehe auch

Kategorien

MATLABLanguage FundamentalsMatrices and ArraysMatrix Indexing

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

  • while loop
  • for loop
  • data
  • database

Produkte

  • MATLAB

Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Es ist ein Fehler aufgetreten

Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.


Translated by Accumulating data in a loop while (10)

Accumulating data in a loop while (11)

Website auswählen

Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .

Sie können auch eine Website aus der folgenden Liste auswählen:

Amerika

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europa

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asien-Pazifik

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Kontakt zu Ihrer lokalen Niederlassung

Accumulating data in a loop while (2024)

References

Top Articles
Toyota Deals & Incentives | New Toyota Special Offers
0% car finance deals 2024 | Best interest free cars (0% APR)
Matgyn
Po Box 7250 Sioux Falls Sd
Genesis Parsippany
Maria Dolores Franziska Kolowrat Krakowská
Don Wallence Auto Sales Vehicles
Kobold Beast Tribe Guide and Rewards
Braums Pay Per Hour
A Fashion Lover's Guide To Copenhagen
Seth Juszkiewicz Obituary
Weekly Math Review Q4 3
Ladyva Is She Married
Cvs Learnet Modules
Driving Directions To Atlanta
MindWare : Customer Reviews : Hocus Pocus Magic Show Kit
Viprow Golf
Transfer and Pay with Wells Fargo Online®
Mals Crazy Crab
Saritaprivate
Busted Campbell County
Diakimeko Leaks
Cor Triatriatum: Background, Pathophysiology, Epidemiology
Hrconnect Kp Login
Ncal Kaiser Online Pay
Used Safari Condo Alto R1723 For Sale
Ripsi Terzian Instagram
Siskiyou Co Craigslist
Steven Batash Md Pc Photos
Ni Hao Kai Lan Rule 34
Joe's Truck Accessories Summerville South Carolina
Uhaul Park Merced
Jefferson Parish Dump Wall Blvd
Page 5662 – Christianity Today
Rage Of Harrogath Bugged
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
Überblick zum Barotrauma - Überblick zum Barotrauma - MSD Manual Profi-Ausgabe
Gotrax Scooter Error Code E2
Valls family wants to build a hotel near Versailles Restaurant
Chase Bank Zip Code
Random Animal Hybrid Generator Wheel
Comanche Or Crow Crossword Clue
St Vrain Schoology
Iman Fashion Clearance
Oakley Rae (Social Media Star) – Bio, Net Worth, Career, Age, Height, And More
Value Village Silver Spring Photos
Legs Gifs
60 Second Burger Run Unblocked
Urban Airship Acquires Accengage, Extending Its Worldwide Leadership With Unmatched Presence Across Europe
Parks And Rec Fantasy Football Names
Myhrkohls.con
Yoshidakins
Latest Posts
Article information

Author: Moshe Kshlerin

Last Updated:

Views: 5964

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Moshe Kshlerin

Birthday: 1994-01-25

Address: Suite 609 315 Lupita Unions, Ronnieburgh, MI 62697

Phone: +2424755286529

Job: District Education Designer

Hobby: Yoga, Gunsmithing, Singing, 3D printing, Nordic skating, Soapmaking, Juggling

Introduction: My name is Moshe Kshlerin, I am a gleaming, attractive, outstanding, pleasant, delightful, outstanding, famous person who loves writing and wants to share my knowledge and understanding with you.