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

Jan
Jan 2013년 7월 8일
What exactly does "load" mean here and where does the 3.14 appear in the posted code?
john
john 2013년 7월 9일
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 2013년 7월 9일
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.

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

 채택된 답변

Jan
Jan 2013년 7월 9일

1 개 추천

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

john
john 2013년 7월 9일
편집: john 2013년 7월 9일
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.
john
john 2013년 7월 10일
:-) yes

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2013년 7월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by