フィルターのクリア

How to replace some data in a tall array by subscript?

5 ビュー (過去 30 日間)
donghai peng
donghai peng 2019 年 6 月 7 日
編集済み: Eva-Maria Weiss 2019 年 8 月 1 日
HP is a tall array, for example, I want to execute HP(n1,n1) = K2Tall; to replace some data by K2Tall. But matlab reported error:For A(m,n,...) = B, m must be either a colon (:) or a tall logical vector. I should how to handle it.
Thanks.
K2Tall=tall(K2);
for ry = 1:m
n1 = [1:l]+(ry-1)*l;
HP(n1,n1) = K2Tall;
end
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 6 月 7 日
編集済み: KALYAN ACHARJYA 2019 年 6 月 7 日
Please share
>> whos HP
>> whos K2Tall
Quentin Garçon
Quentin Garçon 2019 年 6 月 7 日
What is K2 ? Is it a vector, a scalar ?
Anyway, maybe you should try to see the shape of K2 and make sure that the thing you are trying to assign is the same shape on both sides of the equal sign.
If HP is an array, HP(n1, n1), is just a double for example. Is K2 a double ?

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

回答 (2 件)

donghai peng
donghai peng 2019 年 6 月 7 日
K2 is a double array, 12x12; K2Tall=tall(K2), is a 12x12 tall array;HP is 108x108 tall array; n1 =[1,2,3,4,5,6,7,8,9,10,11,12]; i want to replace HP(n1,n1) by K2Tall, HP(n1,n1)=K2Tall; at this time, matlab reported For A(m,n,...) = B, m must be either a colon (:) or a tall logical vector.
Thanks

Eva-Maria Weiss
Eva-Maria Weiss 2019 年 8 月 1 日
編集済み: Eva-Maria Weiss 2019 年 8 月 1 日
Recently I had the same problem.
I solved it by using a tall logical vector for m:
create a tall logical vector: it has to be the same length in the first dimension as your tall array
the rows (n1) that has to be replaced are '1', the others '0'
Number of ones in logical vector equal to size of K2Tall in the first dimension
Position of ones in logical vector corresponds to position in HP you want to replace
To convert a double vector to a tall logical vector I simply used something like that (in a vector already composed of 0s and 1s):
vector = tall(vector == 1);
n1 = zeros(108,1);
n1(1:12,1) = 1;
n1 = tall(n1 == 1);
I hope that helps you!
Good luck!

カテゴリ

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