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

6 次查看(过去 30 天)
results
1
2
3
4
a= [1 2 3 4];
  2 个评论
Tensi Heshan
Tensi Heshan 2021-8-23
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.

请先登录,再进行评论。

采纳的回答

Awais Saeed
Awais Saeed 2021-8-23
Perhaps this is what you want
for col =1:1:4
disp(col)
a(col) = col;
end
disp(['a = ',num2str(a)])
  6 个评论
Awais Saeed
Awais Saeed 2021-8-24
Because you are not storing anything. I am assuming you want to store 'q' values
f = -6:0.001:6;
n = -6:6;
xt = (-2<=n & n<=2);
output = [];
for t = -6:0.001:6
fun = @(f)exp(j.*2.*pi.*f.*t);
q = integral(@(f) fun(f),-2,2);
output = [output q]; % store q values
end
Tensi Heshan
Tensi Heshan 2021-8-24
Right I got the point now, if so i want to assign to a empty array. Thank you for helping me..

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2021-8-23
Read about fprintf and sum.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by