Error:Conversion to cell from double is not possible.

조회 수: 17 (최근 30일)
RAJ
RAJ 2019년 8월 22일
댓글: RAJ 2019년 8월 30일
Dear Programmers
I have a below written code in which I want to run a logical algorithm based on parameters HP and SS with if-else. YM is another parameter which will store the results of the logical statements. HP and SS are 2 cell-array columns which are derived from stress array. YM is another cell-array columns derived a matrix E. "for" loop is executed from row 1 to last row of the stress array so that the values of HP and SS can be evaluated in each row to give a desired value of YM in the YM cell-array following the logical statements.
While executing the code I am receiving the error message: Conversion to cell from double is not possible.
Please help !
N.B: I have attached the txt file for reference.
fID = fopen('no_header.txt','r');
stress=textscan(fID,'%n %n %n','headerlines',7,'Delimiter','');
fclose(fID);
E = zeros(size(stress{1,1}));
YM= num2cell(E);
HP= num2cell(stress{1,2});
SS= num2cell(stress{1,3});
for i= 1:size(stress{1,1},1)
if HP{i}==0 & SS{i}==0
YM(i,1) =1;
elseif HP{i} > 0.15 & SS{i}==0
YM(i,1) = 2;
elseif HP{i} > -0.15 & SS{i} > 5
YM(i,1) = 2;
elseif HP{i} > -0.15 & SS{i} < -5
YM(i,1) = 2;
elseif HP{i} < -0.15
if SS{i} < -15 | SS{i} > 15
YM(i,1) = 10;
else
YM(i,1) = 1000;
end
elseif HP{i} > -0.15 & HP{i} < 0.15 & SS{i} > -5 & SS{i} < 5
YM(i,1) = 6000;
else
warning('CURRENT VALUES OF HP AND SS NOT COVERED BY THIS SIMULATION')
end
end

채택된 답변

Divya Tejaswini
Divya Tejaswini 2019년 8월 23일
Since YM is cell, you need use curly braces { } for indexing to access the contents of cells. YM(i,1) in lines 10, 12, .. 24 has to be replaced to YM{i,1}
  댓글 수: 1
RAJ
RAJ 2019년 8월 30일
Thanks Divya .. It was a silly mistake on my part..Thanks a lot

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by