How to generate a matrix/column of data?

조회 수: 2 (최근 30일)
Alireza Babaei
Alireza Babaei 2021년 3월 11일
답변: Jan 2021년 3월 11일
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에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by