You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
If I have 512 matrices (entries of each matrix is looping modulo 2), how the multiplication syntax for those 512*512 matrices ?
2 views (last 30 days)
Show older comments
Regita Agustin Wahyu F
on 11 Jan 2022
this is syntax for define the 512 matrices
clc,clear;
i=0;
modulo=2;
for A=1:modulo
for B=1:modulo
for C=1:modulo
for D=1:modulo
for E=1:modulo
for F=1:modulo
for G=1:modulo
for H=1:modulo
for I=1:modulo
M=[A-1 B-1 C-1 ; D-1 E-1 F-1 ; G-1 H-1 I-1];
i=i+1;
end
end
end
end
end
end
end
end
end
i
5 Comments
Torsten
on 12 Jan 2022
Edited: Torsten
on 12 Jan 2022
If I have 512 matrices (entries of each matrix is looping modulo 2), how the multiplication syntax for those 512*512 matrices ?
Why 512x512 matrices ? You only have 512 of them.
If you multiply the 512 matrices in arbitrary order, you get the 3x3 zero matrix because one of the 512 matrices is the 3x3 zero matrix.
Regita Agustin Wahyu F
on 12 Jan 2022
i wanna know how the result will be if 512 matrices are multiplied by each itself. next i'll get 262.144 matrices
Torsten
on 13 Jan 2022
Edited: Torsten
on 13 Jan 2022
On my PC, it works fine.
Maybe you changed "m" ?
Then you also have to change the size of the reshaped matrix accordingly:
A = reshape(justRows(i,:),[sqrt(m),sqrt(m)]);
If the error persists, include the code you are using together with the exact error message you receive.
Answers (1)
Torsten
on 12 Jan 2022
Edited: Torsten
on 12 Jan 2022
m = 9;
justRows = dec2bin(0:2^m-1)-'0';
for i = 1:size(justRows,1)
A = reshape(justRows(i,:),[3,3]);
M{i} = A;
end
11 Comments
Walter Roberson
on 6 Jun 2022
How did you initialize M, or how did you ensure that you did not have any old M variable hanging around interfering with the new calculation?
Regita Agustin Wahyu F
on 6 Jun 2022
do you have another idea for this case maybe ? i'm really don't understand
Torsten
on 6 Jun 2022
Edited: Torsten
on 6 Jun 2022
As I see from your screenshot, you still work with your own nested loop solution before you inserted my code lines.
This is wrong because your code defines M as a numerical matrix.
Only use my 6 lines of code:
m = 4;
justRows = dec2bin(0:2^m-1)-'0';
M = cell(2^m,1);
for i = 1:size(justRows,1)
A = reshape(justRows(i,:),[sqrt(m),sqrt(m)]);
M{i} = A;
disp(M{i})
end
0 0
0 0
0 0
0 1
0 1
0 0
0 1
0 1
0 0
1 0
0 0
1 1
0 1
1 0
0 1
1 1
1 0
0 0
1 0
0 1
1 1
0 0
1 1
0 1
1 0
1 0
1 0
1 1
1 1
1 0
1 1
1 1
Torsten
on 6 Jun 2022
Edited: Torsten
on 6 Jun 2022
m = 4;
justRows = dec2bin(0:2^m-1)-'0';
n = size(justRows,1);
M = cell(2^m,1);
for i = 1:n
A = reshape(justRows(i,:),[sqrt(m),sqrt(m)]);
M{i} = A;
end
MM = cell(n^2,1);
for i=1:n
for j=1:n
MM{(i-1)*n+j} = M{i}*M{j};
disp(MM{(i-1)*n+j})
end
end
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 1
0 0
0 0
0 0
0 1
0 0
1 0
0 0
1 1
0 0
1 0
0 0
1 1
0 0
0 0
0 0
0 1
0 0
0 0
0 0
0 1
0 0
1 0
0 0
1 1
0 0
1 0
0 0
1 1
0 0
0 0
0 1
0 0
0 0
0 0
0 1
0 0
1 0
0 0
1 1
0 0
1 0
0 0
1 1
0 0
0 0
0 0
0 1
0 0
0 0
0 0
0 1
0 0
1 0
0 0
1 1
0 0
1 0
0 0
1 1
0 0
0 0
0 0
0 1
0 1
0 0
0 0
0 1
0 1
1 0
1 0
1 1
1 1
1 0
1 0
1 1
1 1
0 0
0 0
0 1
0 1
0 0
0 0
0 1
0 1
1 0
1 0
1 1
1 1
1 0
1 0
1 1
1 1
0 0
0 0
0 0
0 0
0 0
0 1
0 0
0 1
0 0
0 0
0 0
0 0
0 0
0 1
0 0
0 1
0 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0
1 0
1 0
1 0
1 1
1 1
1 1
1 1
1 0
1 0
1 0
1 0
1 1
1 1
1 1
1 1
0 0
0 0
0 0
0 1
0 1
0 1
0 1
0 2
0 0
1 0
0 0
1 1
0 1
1 1
0 1
1 2
1 0
1 0
1 0
1 1
1 1
1 1
1 1
1 2
1 0
2 0
1 0
2 1
1 1
2 1
1 1
2 2
0 0
0 0
0 1
0 0
0 1
0 1
0 2
0 1
1 0
0 0
1 1
0 0
1 1
0 1
1 2
0 1
1 0
1 0
1 1
1 0
1 1
1 1
1 2
1 1
2 0
1 0
2 1
1 0
2 1
1 1
2 2
1 1
0 0
0 0
0 1
0 1
0 1
0 1
0 2
0 2
1 0
1 0
1 1
1 1
1 1
1 1
1 2
1 2
1 0
1 0
1 1
1 1
1 1
1 1
1 2
1 2
2 0
2 0
2 1
2 1
2 1
2 1
2 2
2 2
Torsten
on 6 Jun 2022
Edited: Torsten
on 6 Jun 2022
As you can see above, both codes work with MATLAB R2022a.
I don't know which MATLAB version you have installed and what code lines "coba2" might contain that predefine the cell array M somehow.
I suggest you quit MATLAB and restart it.
Predefining M and MM as
M = cell(2^m,1)
MM = cell(n^2,1)
might help (see above).
Regita Agustin Wahyu F
on 6 Jun 2022
thankyou sir, the last code above finally works in my matlab, but i wanna ask you, does the code above for 16*16=256 matrices ?
Regita Agustin Wahyu F
on 7 Jun 2022
ok thx sir. But can i make MM{(i-1)*n+j} = M{i}*M{j} times MM{(i-1)*n+j} = M{i}*M{j} ? with each MM{(i-1)*n+j} = M{i}*M{j} = 256 matrices if m = 4 as your code above. So later i'll get 65.536 matrices. I'm still confuse how to change the function
Torsten
on 7 Jun 2022
Edited: Torsten
on 7 Jun 2022
I don't understand what you are asking.
Given m, you get 2^m matrices M and 2^(2*m) matrices MM.
So if m = 4, you get 16 matrices M and 256 matrices MM
If m = 9, you get 512 matrices M and 262144 matrices MM.
If m = 16, you get 65536 matrices M and 4294967296 matrices MM. But I doubt you have sufficient RAM to do that.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)