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 个评论

What exactly does "load" mean here and where does the 3.14 appear in the posted code?
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,
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.

请先登录,再进行评论。

 采纳的回答

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 个评论

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');
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})
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.....
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.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by