How to generate a matrix/column of data?

5 ビュー (過去 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 Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by