1xn matrix of variables

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 Comments

How your are determined? Random? Do they follow any equation?
Rik
Rik on 29 Mar 2020
Numbered variables are a bad idea. You should be using an array, as the answer below describes.

Sign in to comment.

 Accepted Answer

Ameer Hamza
Ameer Hamza on 29 Mar 2020
Edited: Ameer Hamza on 29 Mar 2020
Just run
n = 3;
F(3) = 1000;
Result
F =
0 0 1000
It will automatically fill the first two elemets with zero.

2 Comments

k
k on 29 Mar 2020
Wow it was that simple! Thank you!
Glad to be of help.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

k
k
on 29 Mar 2020

Commented:

on 29 Mar 2020

Community Treasure Hunt

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

Start Hunting!