필터 지우기
필터 지우기

Replace certain cell arrays by other cell arrays

조회 수: 1 (최근 30일)
Ahmed Alsaadi
Ahmed Alsaadi 2019년 1월 4일
댓글: Star Strider 2019년 1월 4일
I have this code, I want to replace 0,1,-1 in the first column by T1, T2, T3 respectively and 0,1,-1 by P1, P2, P3 respectively and the same for the third column I want to use S1, S2, and S3 instead of 0, 1, -1. Any ideas?
clc, clear
T = {'T1','T2','T3'}'
PS = {'P1','P2','P3'}'
DS = {'S1','S2','S3'}'
d = bbdesign (3)
dd = num2cell(d)
  댓글 수: 2
Bob Thompson
Bob Thompson 2019년 1월 4일
Where are these 0, 1, -1s that you are referring to?
Ahmed Alsaadi
Ahmed Alsaadi 2019년 1월 4일
If you run the code "bbdesign" function will generate them, it is a design of experiment function. I want to alter the outputs of the function by using my T, P, and S.

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

채택된 답변

Star Strider
Star Strider 2019년 1월 4일
A simple loop seems to work:
idxv = [0; 1; -1];
T = {'T1','T2','T3'}';
PS = {'P1','P2','P3'}';
DS = {'S1','S2','S3'}';
labels = cat(3, T, PS, DS);
d = bbdesign (3);
dd = num2cell(d);
for k1 = 1:size(dd,2) % Columns
for k2 = 1:numel(idxv) % Elements
dd(d(:,k1)==idxv(k2), k1) = labels(k2,k1);
end
end
for k1 = 1:size(dd,1) % Print Results (Delete Later)
fprintf('%s\t%s\t%s\n', dd{k1,:})
end
producing:
T3 P3 S1
T3 P2 S1
T2 P3 S1
T2 P2 S1
T3 P1 S3
T3 P1 S2
T2 P1 S3
T2 P1 S2
T1 P3 S3
T1 P3 S2
T1 P2 S3
T1 P2 S2
T1 P1 S1
T1 P1 S1
T1 P1 S1
It uses simple logical indexing to compare the column entries of °d’ with successive elements of ‘idxv’, and do the replacements. It requires the interim creation of ‘idxv’ and ‘labels’ to make the code reasonably efficient.
  댓글 수: 2
Ahmed Alsaadi
Ahmed Alsaadi 2019년 1월 4일
Thank you very much
Star Strider
Star Strider 2019년 1월 4일
As always, my pleasure.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by