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

6 visualizaciones (últimos 30 días)
results
1
2
3
4
a= [1 2 3 4];
  2 comentarios
Awais Saeed
Awais Saeed el 23 de Ag. de 2021
It is a very basic task. Did you try google search?
Tensi Heshan
Tensi Heshan el 23 de Ag. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Awais Saeed
Awais Saeed el 23 de Ag. de 2021
Perhaps this is what you want
for col =1:1:4
disp(col)
a(col) = col;
end
disp(['a = ',num2str(a)])
  6 comentarios
Awais Saeed
Awais Saeed el 24 de Ag. de 2021
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 el 24 de Ag. de 2021
Right I got the point now, if so i want to assign to a empty array. Thank you for helping me..

Iniciar sesión para comentar.

Más respuestas (1)

KSSV
KSSV el 23 de Ag. de 2021
Read about fprintf and sum.
  2 comentarios
Wan Ji
Wan Ji el 23 de Ag. de 2021
Hi, Keep careful, KSSV
add all numbers to a one array
Tensi Heshan
Tensi Heshan el 23 de Ag. de 2021
No, I want to use for loop and array indexing to the given values of for loop.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by