How can I import data from an excel file and use it for calculations in GUI?

10 views (last 30 days)
Hello everybody,
I have a little problem with the import of an excel file... I want that the user can coose which file is imported with a button. I have a code, but I allways ger an error code, though I'm following suggestions from thee community. In my excel file I got rawdata of meassurements with 4 FSR sensors. Whenever I'm importing the data i can not make calculations within the button callback code. For testing I wanted to show the mean value of each sensor in a text box. Here is my code so far: dataexcel=uigetfile; data=dataexcel; sensor1=data(:,3); sensor2=data(:,4); sensor3=data(:,1); sensor4=data(:,2); mean1=mean(sensor1); set(handles.text2,'string',mean1); mean2=mean(sensor2); set(handles.text3,'string',mean2); mean3=mean(sensor3); set(handles.text4,'string',mean1); mean4=mean(sensor4); set(handles.text5,'string',mean1);
The thing is, that the values should be between 1 and 0.005, but the values seem to be random (102 for example). Can anybody help me? I can not import the data from excel into my workspace... So I can't calculate later on... Is it beacause I do something wrong with the import of the excel file? I am not able to save the parts of the file to variables... Please help me with my problem :)

Accepted Answer

Jan
Jan on 26 Mar 2017
Edited: Jan on 26 Mar 2017
dataexcel=uigetfile; data=dataexcel ???
Then data is the filename of the Excel file. I assume you want the contents of the file:
[FileName, FilePath] = uigetfile();
if isequal(FileName, 0)
disp('User canceled file choosing');
return;
end
data = xlsread(fullfile(FilePath, FileName));
...

More Answers (1)

Felifa
Felifa on 27 Mar 2017
Edited: Felifa on 27 Mar 2017
Hello,
I'm sorry, but there are none error Messages... I got the code right now :) I can add a timescale for 50Hz too. I don't know what I did wrong yesterday but now it works out ;) I asume the reason was, because I did not Import the data right... Thank you very much Jan Simon!!! Here is the code:
[FileName, FilePath]=uigetfile();
data=xlsread(fullfile(FilePath, FileName));
[S1,S2,S3,S4]=getdata(data); %I had a function for getting data
t=0.02*reshape(1:numel(S1),size(S1));
axes(handles.axes1);
plot(t,S1);
xlabel('Time [s]');
ylabel('Voltage [V]');

Categories

Find more on Data Import from MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!