Empty variables and vectors
조회 수: 19 (최근 30일)
이전 댓글 표시
Hi guys, I need your help.
Is it possible to create three empty variables that fill up when a vector connected to the variables reaches a certain value?
I try to explain myself better; there are 3 variables (a, b, c) that affect the values contained within the vector x. What I would like to do is find those values such that the vector, in certain positions, assumes certain values; specifically I would need those 3 values of a, b, c such as to have x (1,1) equal to, for example, 2 and x (1, N) equal to 20.
Is it possible?
Thanks in advance for any help.
댓글 수: 0
답변 (2개)
Constantino Carlos Reyes-Aldasoro
2019년 11월 25일
yes, it is easy
declare the variables as empty:
a =[]; b=[]; c = [];
then run the rest of the code and when you reach your condition (using an if) you can append on the variable
a= [a newValue];
댓글 수: 2
Constantino Carlos Reyes-Aldasoro
2019년 11월 25일
I think we need a bit more information to fully understand each other, but let's see if this helps
you have three variables a,b,c on which a certain vector depends. Let's assume the range is 0 to 100, then try
a=0:100;
b=0:100;
c=0:100;
and the vector is a linear combination
v = 3*(a-20) - 2*b +0.7*c;
plot(v);grid on
and you want the value of a,b,c that make for example v = 25, Then, what you want is
>> a(v==25)
ans =
50
and the same for the other variables
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!