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

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

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.
sortedprioritydata [1.21602018873774 10
-2.22909989155828 10
0.893185966969769 9
1.02908840545717 9
-0.849841587777029 8
2.72704966338821 8
1.65989076612967 7
1.03549829028579 7
0.341240128622871 6
-0.0135126518557689 6
-1.33608880779521 5
-1.80890646939778 5
-1.82840584716151 4
-0.0692502489286168 4
0.810804787327033 3
2.08083166079756 3
3.19758575067649 2
-2.55150643398200 2
2.52199368943212 1
1.94779923722415 1]
this is the main matrix from which we have to place these data into 3 caches named as cache1 cache2 and cache3 in sequence. caches holds data with lru 0 to 7 . size of cache1 is 5,, cache2 size is 7 and cache3 size is 8. now first we place data from main array to cache1 by evicting data whoose lru is <7. if any data in cache1 don't have lru 7 then all will be removed and higher data priority value will place in sequence as you did in above example. similarly when cache1 is full we will go to next cache which is cache2. if first 5 rows of main array replaced the cache1 data then that data will never entered again in cache2 . for example if first 5 data of main array (1.21602018873774, -2.22909989155828, 0.893185966969769,1.0290884054571,-0.849841587777029) replace the data in cache 1 then these values will never enetr again in cache2 similarlry data that replace cache2 data will never enter in cache3.
cache1 [0.814723686393179 0
0.905791937075619 1
0.126986816293506 2
0.913375856139019 3
0.632359246225410 4]
cache2 [0.0975404049994095 0
0.278498218867048 1
0.546881519204984 2
0.957506835434298 3
0.964888535199277 4
0.157613081677548 5
0.970592781760616 6]
cache3 [0.957166948242946 0
0.485375648722841 1
0.800280468888800 2
0.141886338627215 3
0.421761282626275 4
0.915735525189067 5
0.792207329559554 6
0.959492426392903 7
0.655740699156587 1]
for this purpose 1 divided the main array into three chunks chunk1 chunk2 and chunk3. cache1 and chunk 1 has same dimesion 5×2 , cache2 and chunk2 has same dimension 7×2 and cache3 and chunk3 has same dimension 8×2. when I performed the above code to compare chunk1 with cache1 , chunk2 with cache 2 and chunk3 with cache3 it gives error. chunk1 holds first 5 data from main array from inedx 1 to 5. chunk2 holds data from index 6 to 12 and chunk3 holds data from index13 to 20 from main array.
chunk1 [1.21602018873774 10
-2.22909989155828 10
0.893185966969769 9
1.02908840545717 9
-0.849841587777029 8]
chunk2 [2.72704966338821 8
1.65989076612967 7
1.03549829028579 7
0.341240128622871 6
-0.0135126518557689 6
-1.33608880779521 5
-1.80890646939778 5]
chunk3 [-1.82840584716151 4
-0.0692502489286168 4
0.810804787327033 3
2.08083166079756 3
3.19758575067649 2
-2.55150643398200 2
2.52199368943212 1
1.94779923722415 1]
it gives the error I mentioned above and also gives different sizes but all these have same dimensions. kindly help me out to perform such operation thanking in advance.
"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.
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.
Saira
Saira il 2 Mar 2023
Modificato: Saira il 2 Mar 2023
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)
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.

Accedi per commentare.

Risposte (1)

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

Richiesto:

il 28 Feb 2023

Risposto:

il 6 Mar 2023

Community Treasure Hunt

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

Start Hunting!

Translated by