フィルターのクリア

Empty variables and vectors

23 ビュー (過去 30 日間)
Giuseppe Pintori
Giuseppe Pintori 2019 年 11 月 25 日
コメント済み: Giuseppe Pintori 2019 年 11 月 25 日
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.

回答 (2 件)

Constantino Carlos Reyes-Aldasoro
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 件のコメント
Giuseppe Pintori
Giuseppe Pintori 2019 年 11 月 25 日
I don't think I completely understood; what the vector you entered (a) should represent?
Giuseppe Pintori
Giuseppe Pintori 2019 年 11 月 25 日
Also, how it should be the if?
if x(1,1) == 2 && x(1,N) == 20
a = ?
b = ?
c = ?
else
?
end

サインインしてコメントする。


Constantino Carlos Reyes-Aldasoro
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
  1 件のコメント
Giuseppe Pintori
Giuseppe Pintori 2019 年 11 月 25 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by