Hello How to display an =
[ -1/pi, 0, 1/(3*pi), 0, -1/(5*pi), 0, 1/(7*pi)]
in matlab GUI , I have use num2str but it does not work?

댓글 수: 3

Jan
Jan 2017년 5월 10일
Please post your code and explain "does not work" with any details. How should this be displayed? As character string or as numbers?
m
m 2017년 5월 10일
will actually this is if I write an on the command winodw it will display an = [ -1/pi, 0, 1/(3*pi), 0, -1/(5*pi), 0, 1/(7*pi)] the code is just calculation I want to display this result on the GUI, and if I use
set(handles.edit8,'String',num2str(an)) %%nothing is displayed!
Jan
Jan 2017년 5월 10일
@m:
if I write an on the command winodw it will display
an = [ -1/pi, 0, 1/(3*pi), 0, -1/(5*pi), 0, 1/(7*pi)]
What exactly appears in the command window? Do you mean
an = [ -1/pi, 0, 1/(3*pi), 0, -1/(5*pi), 0, 1/(7*pi)]
an =
-0.3183 0 0.1061 0 -0.0637 0 0.0455
? Or do you mean the string
'[ -1/pi, 0, 1/(3*pi), 0, -1/(5*pi), 0, 1/(7*pi)]'
?

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

답변 (2개)

Stephen23
Stephen23 2017년 5월 10일
편집: Stephen23 2017년 5월 10일

0 개 추천

Given a numeric vector, here is one way to generate a string to display:
>> vec = [ -1/pi, 0, 1/(3*pi), 0, -1/(5*pi), 0, 1/(7*pi)]
vec =
-0.31831 0.00000 0.10610 0.00000 -0.06366 0.00000 0.04547
>> [N,D] = rat(vec*pi);
>> C = arrayfun(@(n,d)sprintf('%d/(%d*pi)',n,d),N,D,'uni',0);
>> C = regexprep(C,'0/.*','0');
>> str = sprintf(', %s',C{:});
>> str = sprintf('[%s]',str(3:end))
str = [-1/(1*pi), 0, 1/(3*pi), 0, -1/(5*pi), 0, 1/(7*pi)]
Jan
Jan 2017년 5월 10일

0 개 추천

figure;
H = uicontrol('Style', 'edit', 'Units', 'normalized', 'Position', [0.01, 0.01, 0.98, 0.1]);
an = [ -1/pi, 0, 1/(3*pi), 0, -1/(5*pi), 0, 1/(7*pi)]
set(H, 'String', num2str(an))
Well, this works. Therefore I cannot reconsider, why "nothing is displayed" in your case. Perhaps the foreground color equals the background color of the edit field. Or the handles.edit8 is hidden behind another control. Or you do this in a loop and do not give Matlab the chance to update the display by a drawnow command. There can be a bunch of reasons. Please explain more details and post the relevant part of the code, which reproduces the problem.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

m
m
2017년 5월 10일

답변:

Jan
2017년 5월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by