MATLAB Answers

Empty variables and vectors

3 views (last 30 days)
Giuseppe Pintori
Giuseppe Pintori on 25 Nov 2019
Commented: Giuseppe Pintori on 25 Nov 2019
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.


Sign in to comment.

Answers (2)

Constantino Carlos Reyes-Aldasoro
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];


Giuseppe Pintori
Giuseppe Pintori on 25 Nov 2019
I don't think I completely understood; what the vector you entered (a) should represent?
Giuseppe Pintori
Giuseppe Pintori on 25 Nov 2019
Also, how it should be the if?
if x(1,1) == 2 && x(1,N) == 20
a = ?
b = ?
c = ?

Sign in to comment.

Constantino Carlos Reyes-Aldasoro
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
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 =
and the same for the other variables

  1 Comment

Giuseppe Pintori
Giuseppe Pintori on 25 Nov 2019
The fact is that the code is actually more complicated than what I wrote initially because I wanted to understand the dynamic; furthermore, unfortunately, I cannot publish the code as it is part of a working paper by my supervisor.
My 3 scalars (a, b, c) are used to calculate variables that are contained in a parfor; all this leads to the creation of a 200x200 matrix from which a vector is derived which is the average of the simulations (200x1) and the initial and final value of that vector must be equal to two specific values. Initially I thought of using a fsolve but I can't understand how.
I know that the informations I provided are not many but without being able to publish the code I don't know how to do it.

Sign in to comment.

Sign in to answer this question.