フィルターのクリア

Building matrix using vectors?Easy question.

2 ビュー (過去 30 日間)
STamer
STamer 2013 年 7 月 19 日
P{1}, P{2}...P{n} are my vectors.
And I want P{1} is first row of my matrix.P{2} second row of my matrix. How can I do this?

採用された回答

Iain
Iain 2013 年 7 月 19 日
Depending what you have:
1) matrix = [row_vector1;row_vector2; ... row_vectorn];
2) matrix = [col_vector1, col_vector2, ... col_vectorn]';
3) matrix(row_number1,:) = vector1;
matrix(row_number2,:) = vector2;
matrix(row_number3,:) = vector3;

その他の回答 (2 件)

Jos (10584)
Jos (10584) 2013 年 7 月 19 日
編集済み: Jos (10584) 2013 年 7 月 19 日
Your question suggests you have a cell array with vectors, so you can/should make use of comma-separated list expansion. If all vectors are of the same length, take a look at CAT
P = {1:3,11:13,21:23} % row vectors
M = cat(1,P{:})
If they have different lengths, you might be interested in PADCAT, which pads the vectors with NaNs
P = {[1:3].' , [11:15],' , [21:24],'} % column vectors
M = padcat(P{:}) ;

heybatollah jokar
heybatollah jokar 2013 年 7 月 19 日
*assume you have n vectors with same length which stored in P as follows: P={[vector 1],[vector 2],[vector 3],...}
now using simple code:*
for i=1:length(P)
A(i,:)=P{i}
end
as an example %================================
clc clear all P={[1 2 3],[4,5,6],[7 8 9]}; for i=1:length(P)
A(i,:)=P{i};
end
disp(A) %==============================
% result:
1 2 3
4 5 6
7 8 9
  1 件のコメント
Jos (10584)
Jos (10584) 2013 年 7 月 19 日
why use a for-loop if you have CAT ... (see the answer above for an example)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by