Import Excel and plot
2 ビュー (過去 30 日間)
古いコメントを表示
Hie everyone, i face some problems that i do not actually know where is the problem is. Let's say i have an excel file with two columns. First is 'frequency' and second column is 'data'. When i import the excel file into my GUI, i put two popupmenu two choose for y-axis and x-axis. The problems is, the popupmenu only manage to shows the frequency, for both axis, but not the data. However, when i click the blank space below the frequency which is suppose to be the data words, it manage to plot the graph. So i want to ask, how can i make the data words appear in the popupmenu. Below is the code for my GUI. Regards, Ean
handles.fileName=uigetfile('*.xls') guidata(hObject,handles) setPopupmenuString(handles.popupmenuX,eventdata,handles) setPopupmenuString(handles.popupmenuY,eventdata,handles) set(handles.popupmenuX,'callback','maingui(''updateAxes'',gcbo,[],guidata(gcbo))') set(handles.popupmenuY,'callback','maingui(''updateAxes'',gcbo,[],guidata(gcbo))') function setPopupmenuString(hObject,eventdata,handles)
fileName = handles.fileName;
[numbers,colNames] = xlsread(fileName);
set(hObject,'string',colNames);
function [x,y] = readExcelColumns(fileName,xColNum,yColNum)
a = xlsread(fileName);
x = a(:,xColNum); y = a(:,yColNum);
function updateAxes(hObject,eventdata,handles)
xColNum = get(handles.popupmenuX,'value')
yColNum = get(handles.popupmenuY,'value')
fileName = handles.fileName;
[x,y] = readExcelColumns(fileName,xColNum,yColNum)
plot(handles.axes1,x,y)
0 件のコメント
採用された回答
Matt Tearle
2011 年 2 月 22 日
Run the line [numbers,colNames] = xlsread(fileName); from the Command Window (with the appropriate fileName filled in, obviously) and take a look at colNames. It is almost certainly going to be a whole cell array of text entries. This means that the actual column header strings you want are colNames{1,1} and colNames{1,2}. Because MATLAB is column-major, and allows linear indexing, I suspect that set(hObject,'string',colNames); is essentially getting colNames{1,1} and colNames{2,1} (ie going down the first column). But {2,1} is going to be blank.
So, short answer: replace
set(hObject,'string',colNames);
with
set(hObject,'string',colNames(1,1:2));
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Import from MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!