Data loading in MATLAB

조회 수: 4 (최근 30일)
Fedor Durnev
Fedor Durnev 2020년 2월 4일
댓글: Fedor Durnev 2020년 2월 5일
Hello, I have some issues with data loading.
I have created a figure with some pushbuttons and axes.
Is it possible to load some data for plot building not simply using Y=load('my data.dat') in code?
I mean is it possible to make a button with a function which can open a window where I can choose any file which I want to load? (hope you understand what I am talking about)
Or perhaps, is it possible to make uicontrol where I can put file name and then push the button to load this data and make a plot? I tried to make something following this idea, but failed.
Thank you for help!

채택된 답변

Benjamin Großmann
Benjamin Großmann 2020년 2월 4일
Hi,
have a look at uigetfile and uiopen which open a file selection dialog box. This should solve your issues.
Regards,
Benni
  댓글 수: 2
Fedor Durnev
Fedor Durnev 2020년 2월 4일
uiopen helped, but what's next? How to import this data in the right way, because I need to use it for plot building?
Fedor Durnev
Fedor Durnev 2020년 2월 4일
What should I fix here?
I guess, something with 'load' but I don't know how
function ECGButtonPushed(src,event)
uiopen;
hold on;
Y=load("Normal ECG.dat");
LY=length(Y);
Fd=500;
T=1/Fd;
tmax=LY*T;
t=0:T:tmax-T;
for i=1:LY
Y(i)=Y((i-1)+1);
end
pos1 = [0.05 0.65 0.4 0.3];
subplot('Position',pos1)
plot(t,Y)
xlabel('time,s');
ylabel('ECG,mV');
set(gca,'XLim',[0 20]);
hold on
title('ECG')
end

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

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 2월 4일
Loading the data could be as simple as calling load. The more challenging part is likely to be sharing this data among the various components of your UI. If you're using App Designer, see this documentation page for a description of how to share data between component callbacks. If you're using GUIDE or creating the UI programmatically, see this page instead.
  댓글 수: 2
Fedor Durnev
Fedor Durnev 2020년 2월 5일
Thank you for your answer!
What should I fix here? I guess, something with 'load' but I don't know how function ECGButtonPushed(src,event) uiopen; hold on; Y=load("Normal ECG.dat"); LY=length(Y); Fd=500; T=1/Fd; tmax=LY*T; t=0:T:tmax-T; for i=1:LY Y(i)=Y((i-1)+1); end pos1 = [0.05 0.65 0.4 0.3]; subplot('Position',pos1) plot(t,Y) xlabel('time,s'); ylabel('ECG,mV'); set(gca,'XLim',[0 20]); hold on title('ECG') end
Fedor Durnev
Fedor Durnev 2020년 2월 5일
Managed to do that, many thanks!

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

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by