display numeric value in edit text (matlab GUI)

6 visualizzazioni (ultimi 30 giorni)
raviranjan singh
raviranjan singh il 29 Mag 2018
Commentato: Rik il 4 Giu 2018
fid = fopen('1.txt','r');
indata = textscan(fid, '%d', 'HeaderLines',1);
yourdata = indata{1};
set(handles.edit1,'String',sprintf('%d',yourdata));
fclose(fid);
i write a code to call the numerical value of 1st line, but it not display in edit text after run in matlab gui.
  1 Commento
Rik
Rik il 4 Giu 2018
Did either answer work for you? If so, please accept the answer that works best, if not, please explain how the results of the provided code are different from what you want.

Accedi per commentare.

Risposte (2)

Walter Roberson
Walter Roberson il 29 Mag 2018
Your results in yourdata are almost certainly a column vector of values. When you sprintf() a vector of numeric values, sprintf() will put the results into one continuous row vector. You used %d format without any delimiters so the result would be just one long stream of digits (with perhaps an occasional negative sign mixed in.)
If you change from sprintf to sprintfc then the result of the sprintf will be a cell array of values, which will be suitable for setting the String property to provided that when you created edit1 that you created it with Max property at least 2.
  2 Commenti
raviranjan singh
raviranjan singh il 29 Mag 2018
not working, my problem is that to call the numerical value from text 1st line and display in edit text. similarity for 2nd and 3rd line for respective edit text.
Walter Roberson
Walter Roberson il 29 Mag 2018
set(handles.edit1,'String',sprintf('%d',yourdata(1)));
set(handles.edit2,'String',sprintf('%d',yourdata(2)));
set(handles.edit3,'String',sprintf('%d',yourdata(3)));

Accedi per commentare.


Rik
Rik il 29 Mag 2018
Instead of posting a new question and closing the old question, you should have explained what was wrong.
In this case, you need to set the Max property of your uicontrol element to allow multiple lines of text.
yourdata=9:12;
figure(1),clf(1)
handles.edit1=uicontrol('style','edit','units','normalized','position',[0.1 0.1 0.8 0.8]);
str=cellfun(@(x) sprintf('%f',x),num2cell(yourdata),'UniformOutput',0);
set(handles.edit1,'Max',numel(str))
set(handles.edit1,'String',str)

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by