Error:Conversion to cell from double is not possible.

17 vues (au cours des 30 derniers jours)
RAJ
RAJ le 22 Août 2019
Commenté : RAJ le 30 Août 2019
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

Réponse acceptée

Divya Tejaswini
Divya Tejaswini le 23 Août 2019
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 commentaire
RAJ
RAJ le 30 Août 2019
Thanks Divya .. It was a silly mistake on my part..Thanks a lot

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by