1xn matrix of variables

3 次查看(过去 30 天)
k
k 2020-3-29
I need to create a one column matrix F where for n inputs, there are n F values.
For example:
n = 3:
F = F1
F2
F3
I know that I need to create a for loop this but I'm not sure how to do it.
And then I need an if statement saying that for all F(<n), F(<n) = 0 and F(n) = 1000.
In this example, F1 = 0 and F2 = 0, but F3 = 1000.
  2 个评论
sergi quintana
sergi quintana 2020-3-29
How your are determined? Random? Do they follow any equation?
Rik
Rik 2020-3-29
Numbered variables are a bad idea. You should be using an array, as the answer below describes.

请先登录,再进行评论。

采纳的回答

Ameer Hamza
Ameer Hamza 2020-3-29
编辑:Ameer Hamza 2020-3-29
Just run
n = 3;
F(3) = 1000;
Result
F =
0 0 1000
It will automatically fill the first two elemets with zero.
  2 个评论
k
k 2020-3-29
Wow it was that simple! Thank you!
Ameer Hamza
Ameer Hamza 2020-3-29
Glad to be of help.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by