arrays with same dimensions but have different size how to fix it?
Mostra commenti meno recenti
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 Commenti
Dyuman Joshi
il 28 Feb 2023
What is the operation you are trying to perform?
Please attach any relevant code and data using the paperclip button or you can copy and paste it. And mention which version of MATLAB you are using.
Saira
il 1 Mar 2023
Voss
il 1 Mar 2023
"when I performed the above code to compare chunk1 with cache1 , chunk2 with cache 2 and chunk3 with cache3 it gives error."
What code? The code you've posted so far appears to be intended to assign values to various variables, but it does no comparisons.
Please share the actual code that produces the error.
Dyuman Joshi
il 2 Mar 2023
cache3 doesn't have size 8x2, it is 9x2
And as Voss mentioned, please share the actual code you are using, that produces the error.
Mention the version of MATLAB you are using as well. I requested this earlier but you did not answer this query.
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
chunk1(:,2) is nowhere equal to 11, so the right-hand side is empty.
Risposte (1)
Arka
il 6 Mar 2023
0 voti
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).
Categorie
Scopri di più su Resizing and Reshaping Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!