How to fill a preallocated matrix with function output?

3 ビュー (過去 30 日間)
Michael
Michael 2014 年 6 月 29 日
コメント済み: Michael 2014 年 6 月 29 日
Hi there.
I've preallocated a zeros(10,4) matrix. I'm trying to store the result or "fill" each row with the output of another function (that I didn't write). The output of the function is a 1x4 array (i.e. [1 2 3 4]). I effectively want to replace each row with "ans" but I know that's just not cool.
I assume this is done by concatenation... However, the best I can do is add to the array... but there's still the 10x4 zeros below it. Is there a way to do it with indices/for loop? I'm up for whatever's easiest.
example:
A = zeros(10,4) and my 1x4 output = [1 2 3 4]
How would I replace A's first row with [1 2 3 4] without just "adding" to it?
Thanks!

採用された回答

Roger Stafford
Roger Stafford 2014 年 6 月 29 日
編集済み: Roger Stafford 2014 年 6 月 29 日
A(r,:) = [1 2 3 4];
or
A(r,:) = 1x4 output of function
These place the 1x4 array in the r-th row.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by