How to generate a matrix/column of data?

4 visualizzazioni (ultimi 30 giorni)
Alireza Babaei
Alireza Babaei il 11 Mar 2021
Risposto: Jan il 11 Mar 2021
Dear scholars,
suppose I have two input data set: a = [1, 2] and b = [11, 12]. Now v as the output will be: v = [f(a(1),b(1)), f(a(1),b(2)); f(a(2),b(1)), f(a(2),b(2))] which is a 2*2 matrix with 4 entities.
Now I need to generate a data set in Excel such that the first column is a, the second column is b and the 3rd column will be v. This matrix will be 4*3. I am not sure how to write such a code for this.
Any ideas?
a = [1, 2]
b = [11, 12]
for i = 1 : length(a)
for j = 1 : length(b)
%v = 2*a(i) + b(j)
v(i,j) = 2*a(i) + b(j)
MA = [a(i); b(j); v(i,j)]
%ab(i,j) = [a(i), b(j)]
end
end

Risposta accettata

Jan
Jan il 11 Mar 2021
a = [1, 2];
b = [11, 12];
MA = zeros(4, 3);
k = 0;
for i = 1 : length(a)
for j = 1 : length(b)
%v = 2*a(i) + b(j)
v = 2*a(i) + b(j);
k = k + 1;
MA(k, :) = [a(i), b(j), v];
end
end

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by