I have a 6×37 matrix of values ranging from 1-6 which are classes. stability_class is attached.
I want to assign values to four matrices a,b,d,e to be the same dimension with stability_class and have different entries when stability_class changes from 1-6 across rows and columns.
a=zeros(size(X));
b=zeros(size(X));
d=zeros(size(X));
e=zeros(size(X));
[c,f]=find(stability==1);
ind=[c,f];
i=ind(1:end,:);
j=ind(:,1:end);
for k=1:size(c,1)
a(i(k,1),j(k),2)=0.32;
b(i(k,1),j(k,2))=0.0004;
d(i(k,1),j(k,2))=0.24;
e(i(k,1),j(k,2))=0.0001;
end
[c, f]=find( stability==2);
ind=[c,f];
i=ind(1:end,:);
j=ind(:,1:end);
for k=1:size(c,1)
a(i(k,1),j(k,2))=0.32;
b(i(k,1),j(k,2))=0.0004;
d(i(k,1),j(k,2))=0.24;
e(i(k,1),j(k,2))=0.0001;
end
[c,f]=find(stability==3) ;
ind=[c,f];
i=ind(1:end,:);
j=ind(:,1:end);
for k=1:size(c,1)
a(i(k,1),j(k,2))=0.16;
b(i(k,1),j(k,2))=0.0004;
d(i(k,1),j(k,2))=0.12;
e(i(k,1),j(k,2))=0.00;
end
[c,f]= find(stability==4);
ind=[c,f];
i=ind(1:end,:);
j=ind(:,1:end);
for k=1:size(c,1)
a(i(k,1),j(k,2))=0.16;
b(i(k,1),j(k,2))=0.0004;
d(i(k,1),j(k,2))=0.12;
e(i(k,1),j(k,2))=0.00;
end
[c,f]=find(stability==5);
ind=[c,f];
i=ind(1:end,:);
j=ind(:,1:end);
for k=1:size(c,1)
a(i(k,1),j(k,2))=0.16;
b(i(k,1),j(k,2))=0.0004;
d(i(k,1),j(k,2))=0.14;
e(i(k,1),j(k,2))=0.0003;
end
[c,f]=find(stability==6);
ind=[c,f];
i=ind(1:end,:);
j=ind(:,1:end);
for k=1:size(c,1)
a(i(k,1),j(k,2))=0.11;
b(i(k,1),j(k,2))=0.0004;
d(i(k,1),j(k,2))=0.08;
e(i(k,1),j(k,2))=0.0015;
end
But I get a 3D array(x:y:z) for a with uncompleted matrices for b,d,e.

댓글 수: 2

KSSV
KSSV 2020년 8월 28일
Question is not clear. What output you expect?
Aduloju Oluwatobi
Aduloju Oluwatobi 2020년 8월 28일
I want q 6×37 matrix for a,b,d,e

댓글을 달려면 로그인하십시오.

 채택된 답변

Bruno Luong
Bruno Luong 2020년 8월 28일

0 개 추천

a=zeros(size(stability));
b=zeros(size(stability));
d=zeros(size(stability));
e=zeros(size(stability));
ind=find(stability==1);
a(ind)=0.32;
b(ind)=0.0004;
d(ind)=0.24;
e(ind)=0.0001;
ind=find( stability==2);
a(ind)=0.32;
b(ind)=0.0004;
d(ind)=0.24;
e(ind)=0.0001;
ind=find(stability==3) ;
a(ind)=0.16;
b(ind)=0.0004;
d(ind)=0.12;
e(ind)=0.00;
ind= find(stability==4);
a(ind)=0.16;
b(ind)=0.0004;
d(ind)=0.12;
e(ind)=0.00;
ind=find(stability==5);
a(ind)=0.16;
b(ind)=0.0004;
d(ind)=0.14;
e(ind)=0.0003;
ind=find(stability==6);
a(ind)=0.11;
b(ind)=0.0004;
d(ind)=0.08;
e(ind)=0.0015;

댓글 수: 3

If you want more compact code put values in the Lookup Table rather than hard code it.
LUT=[...
0.32, 0.0004, 0.24, 0.0001;
0.32,0.0004,0.24,0.0001;
0.16,0.0004,0.12,0.00;
0.16,0.0004,0.12,0.00;
0.16,0.0004,0.14,0.0003;
0.11,0.0004,0.08,0.0015 ...
];
LUTfun = @(col) reshape(LUT(stability,col),size(stability));
a=LUTfun(1);
b=LUTfun(2);
c=LUTfun(3);
d=LUTfun(4);
Stephen23
Stephen23 2020년 8월 28일
find is not required, would be simpler and more efficient without.
Bruno Luong
Bruno Luong 2020년 8월 28일
I know I just want to change little to OP's code so he can still follow.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

제품

릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by