how create matrix 8*8
Show older comments
Hi, can someone help me with this code
I want to create a 8*8 matrix using equation
No value should be repeated within the array
That is, each value in the array appears one time only.
clear all;clc;
r=0.2;x(1,1)=0.8;
for i=2:64
x(i)=r+(1-x(i-1))^2;
end
A=reshape(x,8,[]);
for i=1:8
for j=1:8
allma(i,j)=A(i,j);
end
end
ssA= [];b=[]
for i=1: 8
for j=1:8
ZZZZ=A(i,j);
ssA(i,j)=round(mod(ZZZZ*10^5,256));
end
end
ssA =
128 151 252 249 49 224 191 178
192 60 40 63 172 217 235 242
192 145 73 180 21 213 187 176
114 69 136 100 187 223 237 243
43 11 190 126 255 204 183 175
2 16 212 130 200 228 239 244
86 225 80 83 238 197 180 173
220 174 15 154 209 232 241 245
4 Comments
Jan
on 8 Feb 2021
allma is not used anywhere, so you can omit the corresponding two loops.
A faster version for the final loops:
ssA = round(mod(A*1e5, 256));
So you do not need loops for this.
Jan
on 7 Mar 2021
@sarah: Please do not remove important parts of the question, because this let the answers become useless for other readers. The nature of this forum is that voluntary other users helps you to solve your problem, but this is not a cheap debugging service, but thought for sharing solutions ith the community. Then deleteing parts of the question is a missusage of the work of the persons, who help you.
@sarah: You have removed the code again in this and several other of your questions. If you have a good reasons to delete it, contact one of the editors or the admins of the forum and explain the problem.
For the readers: Here is the code which was part of the question initially:
clear all;clc;
r=0.2;x(1,1)=0.8;
for i=2:64
x(i)=r+(1-x(i-1))^2;
end
A=reshape(x,8,[]);
for i=1:8
for j=1:8
allma(i,j)=A(i,j);
end
end
ssA= [];b=[]
for i=1: 8
for j=1:8
ZZZZ=A(i,j);
ssA(i,j)=round(mod(ZZZZ*10^5,256));
end
end
ssA =
128 151 252 249 49 224 191 178
192 60 40 63 172 217 235 242
192 145 73 180 21 213 187 176
114 69 136 100 187 223 237 243
43 11 190 126 255 204 183 175
2 16 212 130 200 228 239 244
86 225 80 83 238 197 180 173
220 174 15 154 209 232 241 245
Rena Berman
on 6 May 2021
(Answers Dev) Restored edit
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!