How to generate a matrix/column of data?

5 次查看(过去 30 天)
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

采纳的回答

Jan
Jan 2021-3-11
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by