Plotting Data by Using Loaded TXT File and Gui Pushbutton Problem
Mostrar comentarios más antiguos
Dear, everyone. I have a problem with my Gui Pushbutton Script to plt my loaded txt data here... This is my script :
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
formku = guidata(gcbo);
[namafile,direktori]=uigetfile('*.txt','Load Data Magnet LEMI RAW','Multiselect','on');
eval(['cd ''' direktori ''';']);
eval(['mydata=load(''' namafile ''')']);
tahun = mydata(:,1); %: Getting data in column 1
bulan = mydata(:,2); %: Getting data in column 2
tanggal = mydata(:,3); %: Getting data in column 3
jam = mydata(:,4); %: Getting data in column 4
menit = mydata(:,5); %: Getting data in column 5
detik = mydata(:,6); %: Getting data in column 6
kompx = mydata(:,7); %: Getting data in column 7
kompy = mydata(:,8); %: Getting data in column 8
kompz = mydata(:,9); %: Getting data in column 9
w = seconds((3600*jam)+(60*menit)+ detik);
w.Format = 'hh:mm';
D = datetime(tahun,bulan,tanggal,jam,menit,detik,'TimeZone','Asia/Jakarta');
s = (w/86400)+tanggal;
for i=1:length(detik)
hmagnet = sqrt((kompx.^2)+(kompy.^2));
fmagnet = sqrt((kompx.^2)+(kompy.^2)+(kompz.^2));
end
p = plot(D, hmagnet);
xlabel('Time Series','fontweight','bold','fontsize',10);
ylabel('Horizontal Magnetic Component Of Non IAGA Lemi Format (nT)','fontweight','bold','fontsize',10);
legend('off');
set(formku.figure1,'CurrentAxes',formku.satu);
set(p,'LineWidth',1);
set(formku.satu,'Color',[1 0.96 0.9],...
'XGrid','on',...
'YGrid','on',...
'NextPlot','add');
set(formku.figure1,'Userdata',mydata);
grid on
I just want to get the desired column data to be calculated by using Pythagoras formula as hmagnet or fmagnet data column and then plotting the result versus TIME data in D variable on my GUI .fig program but it never happened.

It just show me as a blank cartesian default figure.... So everyone, im so grateful if you help my problem here... Thank you very much...
10 comentarios
Rik
el 6 de Jul. de 2021
As you have been asked in your previous question:
- Why are you using eval and cd? You need to use fullfile to compose the input for load.
- Have you tried using the debugger do step through your code line by line?
There are several steps to what you want to do. First the reading of your file, then the parsing of those contents to the variables you want to plot, then the plotting itself. Which of these steps is causing the issue?
I would also suggest using English comments to explain your code. That will make it easier for people on this forum. The overwhelming majority can read/write English, but only few visitors will be able to read Indonesian without Google Translate.
Tyann Hardyn
el 6 de Jul. de 2021
Editada: Tyann Hardyn
el 6 de Jul. de 2021
Rik
el 6 de Jul. de 2021
[namafile,direktori]=uigetfile('*.txt','Load Data Magnet LEMI RAW','Multiselect','on');
mydata=load(fullfile(direktori,namafile));
Note that the user could select multiple files, resulting in an error when using load.
So now we have removed cd and load. Did you set a breakpoint to step through your code?
Another suggestion:
p = plot(D, hmagnet,'Parent',formku.handle_to_your_axes);
You should do this for every to any graphics object.
And why are you storing the array to the UserData, instead of the guidata struct?
Tyann Hardyn
el 7 de Jul. de 2021
Rik
el 7 de Jul. de 2021
The handle to your axes object. You seem to be using GUIDE (even though that's a bad idea), so it is probably called formku.axes1
Tyann Hardyn
el 7 de Jul. de 2021
Editada: Tyann Hardyn
el 7 de Jul. de 2021
Rik
el 7 de Jul. de 2021
You're making it hard to help you. Why haven't you applied my suggested edit?
GUIDE will automatically generate handles. Why don't you use those instead? And why did you not edit the call to plot?
And did you already try using breakpoints to step through the code line by line?
Tyann Hardyn
el 8 de Jul. de 2021
Editada: Tyann Hardyn
el 8 de Jul. de 2021
Tyann Hardyn
el 8 de Jul. de 2021
Rik
el 8 de Jul. de 2021
One minor addition: the handles struct is already loaded, so your first line is not required.
I guessed your language by pasting your comments in Google translate.
Respuestas (0)
Categorías
Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
