Load real number, not integer

Hi,
why is not possible to load real number? For example "3.14"???
It works only with integer.
UserData.matrix(1,1)=num2cell(sym(char(strcat('_',get(handles.a,'String'),char(sym(UserData.matrix{1,1}))))));
Can you help me?

3 commentaires

Jan
Jan le 8 Juil 2013
What exactly does "load" mean here and where does the 3.14 appear in the posted code?
john
john le 9 Juil 2013
Sorry...I changed the code.
From edit text "a" a want load real number and than save into matrix.
I use matrix forexample for saving informations into folder,
Jan
Jan le 9 Juil 2013
The question is still not clear. Why do you add a leading underscore? Why do you make the expression symbolic? You can save informations to a folder, but to a file only. But even then it is not clear, how the extraction of the cell element UserData.matrix{1,1} is related to a loading.
So I try to guess a solution, but thuis does not match to your posted code in any way.

Connectez-vous pour commenter.

 Réponse acceptée

Jan
Jan le 9 Juil 2013

1 vote

From the text of your question, I'd extect this could be a solution:
UserData.matrix{1,1} = sscanf(get(handles.a, 'String'), '%g');

5 commentaires

john
john le 9 Juil 2013
Modifié(e) : john le 9 Juil 2013
Hi,
UserData.matrix is matrix of type cell. I store in this matrix many informations, real numbers, characters, strings.
I try to save into cell UserData.matrix{1,1} real numbers. I want to store in this cell {1,1} more numbers, not only one. My idea was to use underscore to devide individual numbers. Therefore I used strcat- for connecting new and old numbers.
And also I need store into UserData.matrix{1,2} strings. These strings have to be also devided from each other.
And also than I need get back individual numbers, strings
For saving matrix I use this code:
cm=size(UserData.matrix);
for i=1:cm(1);
for j=1:cm(2);
data(i,j)=sym(UserData.matrix{i,j});
end;
end;
vys=size(data);
for i=1:vys(1);
for j=1:vys(2);
vysledok(i,j)=cellstr(char(data(i,j)));
end;
end;
UserData.save=vysledok;
data=UserData.save;
save(fullfile(PathName, FileName), 'data');
Jan
Jan le 9 Juil 2013
Please do not use "save" for storing variables in a cell. "save" usually means writing to disk.
It is unclear how and underscore should help to store numbers in a cell. This does not sound like Matlab.
Perhaps this helps:
M = cell(2, 2);
M{1,1} = 3
M{1,1} = [M{1,1}, 4];
M{1,1} = [M{1,1}, 5];
M{1,2} = {'1st string'}; % A nested cell!
M{1,2}{2} = {'2nd string'}; % Nested cell indexing!
disp(M{1,1})
disp(M{1,2})
john
john le 9 Juil 2013
Hi,
I use save, cause I want a write it on a disk....
Based on underscore I can find out and divide each numbers.
I changed code:
UserData.matrix{1,1}=sscanf(strcat('||',get(handles.a, 'String'),char((UserData.matrix{1,1}))), '%s');
vys=size(UserData.matrix);
for i=1:vys(1);
for j=1:vys(2);
vysledok(i,j)=cellstr(char(UserData.matrix{i,j}));
end;
end;
UserData.save=vysledok;
data=UserData.save;
save(fullfile(PathName, FileName), 'data');
And it looks like it works....I have to test it now.....
Jan
Jan le 9 Juil 2013
I cannot imagine what the conversions in these two lines should do:
UserData.matrix{1,1}=sscanf(strcat('||',get(handles.a, 'String'), ...
char((UserData.matrix{1,1}))), '%s');
vysledok(i,j)=cellstr(char(UserData.matrix{i,j}));
I have the strong impression that this can be done much more direct, but when it works as expected, who cares.
john
john le 10 Juil 2013
:-) yes

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by