How to generate a matrix/column of data?

5 Ansichten (letzte 30 Tage)
Alireza Babaei
Alireza Babaei am 11 Mär. 2021
Beantwortet: Jan am 11 Mär. 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

Akzeptierte Antwort

Jan
Jan am 11 Mär. 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

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by