How to print numbers 1 to 4 and add all numbers to a one array?

15 views (last 30 days)
results
1
2
3
4
a= [1 2 3 4];
  2 Comments
Tensi Heshan
Tensi Heshan on 23 Aug 2021
yes I did. Here 1 2 3 4 are taken from loop and all the values (elements) are assigned to a variable "a".
I can don separately but I could not do it together.

Sign in to comment.

Accepted Answer

Awais Saeed
Awais Saeed on 23 Aug 2021
Perhaps this is what you want
for col =1:1:4
disp(col)
a(col) = col;
end
disp(['a = ',num2str(a)])
  6 Comments
Tensi Heshan
Tensi Heshan on 24 Aug 2021
Right I got the point now, if so i want to assign to a empty array. Thank you for helping me..

Sign in to comment.

More Answers (1)

KSSV
KSSV on 23 Aug 2021
Read about fprintf and sum.

Community Treasure Hunt

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

Start Hunting!

Translated by