Choose my k-term from matrix and defines by itself on for loop
Ältere Kommentare anzeigen
Suppose i have n×1 matrix before, (column vector), namely "x1" (i'm defining this matrix with x1). I can't write my x1 because of it depends on my input. And this matrix could be 3×1, 7×1, until n×1. In this case i won't mention it on my script below
x1
for c=1:10
for d=0:9
'a',c,=x1(c,1)
end
end
My wish is when i have x1 is matrix of 10×1 (Look at my c) my for loop will display
a1=
2
a2=
3
.
.
.
a10=
4
2, 3, 4 are arbitrary numbers depend on my input of matrix x1. That means, i want it defines a variable by itself generating from my "c" (Look at my fourth line)
And that 'a',c, can be used for evaluating another formula.
For example
Px=a1+a2+a3
Is that possible? Thanks. If my question is not clear, please tell me.
EDIT :
Another alternative in my thought is the following: For example, i want to construct summation
My attempt is:
x1
for c=1:10
for d=0:9
P=sum((x1(c,1)))*9^d
end
end
But it's Not work and displays weird thing.
As i said before, actually my goal is evaluating the k-element in my matrix that is i take it randomly (not literally "random") And construct it as like this:
Where
is the k-element from my matrix, and x is just independent variable in that equation and depend on my input.
I've edit my question. I hope it's clear now and tell me if it's not. Thanks again.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!