arrays with same dimensions but have different size how to fix it?

4 ビュー (過去 30 日間)
Saira
Saira 2023 年 2 月 28 日
回答済み: Arka 2023 年 3 月 6 日
I have two arrays both have same dimension 5x2 but when i perfom certain operation on both array it gives error Assignment has more
non-singleton rhs dimensions than non-singleton subscripts and also their sizes are also different. how to fix this issue kindly help me out thanking in advance.
  6 件のコメント
Saira
Saira 2023 年 3 月 2 日
編集済み: Saira 2023 年 3 月 2 日
I'm using R2015b.
for i = 1: size(cache1,1)
if cache1(i,2) < 6
ind = 11 - cache1(i,2);
cache1(i,1) = max(chunk1(chunk1(:,2) == ind));
end
end
result_arr = cache1(:,1)
Voss
Voss 2023 年 3 月 2 日
cache1 = [
0.814723686393179 0
0.905791937075619 1
0.126986816293506 2
0.913375856139019 3
0.632359246225410 4];
chunk1 = [
1.21602018873774 10
-2.22909989155828 10
0.893185966969769 9
1.02908840545717 9
-0.849841587777029 8];
for i = 1: size(cache1,1)
if cache1(i,2) < 6
ind = 11 - cache1(i,2)
cache1(i,1) = max(chunk1(chunk1(:,2) == ind));
end
end
ind = 11
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-1.
chunk1(:,2) is nowhere equal to 11, so the right-hand side is empty.

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

回答 (1 件)

Arka
Arka 2023 年 3 月 6 日
Hi,
In the code sample that you shared, chunk1(:,2) == ind returns a 5x1 logical array containing only zeros.
Since MATLAB uses 1-indexed arrays, chunk1(chunk1(:,2) == ind) returns a 0×1 empty double column vector, and hence you get the error.
This is happening because none of the values in the second column of chunk1 match the value of 11 - cache1(i,2).

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by