필터 지우기
필터 지우기

Import Excel and plot

조회 수: 2 (최근 30일)
Ean Soo
Ean Soo 2011년 2월 22일
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)

채택된 답변

Matt Tearle
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));
  댓글 수: 1
Ean Soo
Ean Soo 2011년 2월 22일
THanks Matt, you give me a better understanding on this

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by