how can i store data in zero matrix

Suppose I have a 8*150 matrix contain zeros. And I have 2 vectors, each one contain 8 numbers. How can I insert each row in the matrix, a vector that is calculated from the tow vectors? What I mean is for example; Lets say I have vector a=[18116 24439 41953 2131 10783 11630 38957 16955]; And vector b=[18234 24564 42066 2229 10906 11732 39061 17068]; And I want to insert to row number 1 of the matrix 8*150(the zero matrix) the index a(1):b(1) And I want to insert to row number 2 of the matrix 8*150(the zero matrix) the index a(2):b(2) The problem is that the length of the vector of every row is different

 採用された回答

Matt J
Matt J 2012 年 10 月 3 日

2 投票

The fastest way would probably be as follows, though I doubt speed is critical for you if its only an 8-row matrix.
Z=zeros(8,150);
for i=1:length(a)
insert=a(i):b(i);
Z(i,1:length(insert))=insert;
end

その他の回答 (1 件)

maor
maor 2012 年 10 月 13 日

0 投票

that work perfectly.thank you very much

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2012 年 10 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by