whats wrong with this code?

1 ビュー (過去 30 日間)
Muazma Ali
Muazma Ali 2022 年 8 月 30 日
コメント済み: Muazma Ali 2022 年 9 月 23 日
I have a while loop as shown in the attached file and all these variables
combinations_of_salts, vekt_prosent_best_salt_1,
Are set within the loop
The code relevant for the error that occurred is included in the file.
I get the following error saying:
Conversion to double from cell is not possible.
The error points to this line:
Osmotisk_data(nr_zones_analyzed,:)={nr_zones_analyzed, combinations_of_salts, vekt_prosent_best_salt_1,vekt_prosent_best_salt_2, samlet_vannaktivitet,Osmotic_pressure}
And it occurs when I have run the code for antall_soner = 2.
Can anybody tell me whats wrong with this code..? :)

回答 (2 件)

Image Analyst
Image Analyst 2022 年 8 月 30 日
I didn't look at your code but from the sounds of it you're probably trying to do this with your cell array
dbl = str2double(ca(1));
when you should be using braces to get the contents of the cell, like this:
dlb = str2double(ca{1});
See the FAQ:
It will tell you when to use parentheses, braces, or brackets.
  4 件のコメント
Image Analyst
Image Analyst 2022 年 8 月 30 日
No I cannot overlook (ignore) the fact that the "beregn_osmotisk_trykk" function is missing. Your code won't run without it. You must give it to us if you want our help.
Also I think you overlooked my request for the inputs that should be entered, because you did not tell us any of them. What numbers do we tell your program?


Walter Roberson
Walter Roberson 2022 年 8 月 30 日
varType=["double", "double", "double", "double", "double", "string"];
varNames=["Zone_nr", "Combinations_of_salts", "Weight_percent_best_salt_1", "Weight_percent_best_salt_2", "Total_water_activity", "Osmotic_pressure"];
So Combination_of_salts must be a double.
C(nr_zones_analyzed, 1)=string(best_salt_1)+ ' ' + string(best_salt_2);
Entries in C are string
So combinations_of_salts is string array.
Osmotisk_data(nr_zones_analyzed,:)={nr_zones_analyzed, combinations_of_salts, vekt_prosent_best_salt_1,vekt_prosent_best_salt_2, samlet_vannaktivitet,Osmotic_pressure}
combinations_of_salts is being sent to the second column of the table, and the second column of the table must be double, but the source is string array.
  5 件のコメント
Muazma Ali
Muazma Ali 2022 年 9 月 23 日
@Walter Roberson It worked for some time then I got same error message when I ran my own program.
And if I run this file attached which is a shorter version of my prog, I dont get anything out for combinations of salts field.. :(
Please help me with my problem



Find more on Cell Arrays 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!

Translated by