error: Index exceeds matrix dimensions

i have created an eatable with two columns , a plot button and two buttons for editing the row's number(add/delete), the ColumnFormat is char .the first column contains the function's body (for example sin(t) ) , and the second column contains the time limit , that i want to plot the function between it (for example [10 50]).when i press the plot button , on the command window appears the following error : 'Index exceeds matrix dimensions.' where is the mistake in the code ?
here is the plot callback function
D=cell2mat(get(handles.table,'data'));
if size(D,1)==1 %number of rows
T1=str2num(D(1,2));
X1=str2func(['@(t)' D(1,1)]);
fplot(X1,T1,'Parent',handles.axes1);
else
for i=1:size(D,1)
Ti=str2num(D(i,2));
Xi=str2func(['@(t)' D(i,1)]);
fplot(Xi,Ti,'Parent',handles.axes1);
hold(handles.axes1, 'on')
end
end
hold(handles.axes1, 'off')
grid on

댓글 수: 7

Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 27일
Post the entire error message
Elia
Elia 2013년 12월 27일
편집: Azzi Abdelmalek 2013년 12월 27일
Index exceeds matrix dimensions.
Error in fplot (line 96)
xmin = min(lims(1:2)); xmax = max(lims(1:2));
Error in Sprov>XfuncTable_plot_Callback (line 453)
fplot(X1,T1,'Parent',handles.axes2);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Sprov (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)Sprov('XfuncTable_plot_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
xmin = min(lims(1:2)); xmax = max(lims(1:2));
What's lims and where's it supposed to have come from?
Azzi Abdelmalek
Azzi Abdelmalek 2013년 12월 27일
This is from fplot function
dpb
dpb 2013년 12월 27일
Ahhhh...indeed! My bad.
Looks to me like he's got a formatting problem in defining his input to the function -- he gives as an example that the function string is sin(t) and wants to plot the function between two limits that he gives as a vector [10 50]. I've not done this specifically and it's not convenient at the moment to fire up Matlab to test but I'm thinking needs to pass the range as the vector [10:50]?
But still not sure that'll cure the internal problem...
Elia
Elia 2013년 12월 28일
편집: Elia 2013년 12월 28일
What exactly do you mean with '' needs to pass the range as the vector [10:50] '' ?
Jan
Jan 2013년 12월 28일
@Sam: Please do not post a question in multiple forums. If you have a really good reason to do so, add at least a link to the other forum. Otherwise the voluntary helpers might waste time with posting an answer, which has been given elsewhere already. Thanks.

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

답변 (2개)

Lennart
Lennart 2013년 12월 27일

0 개 추천

Try the squeeze() command, sometimes non functional extra dimensions are created which give these kinds of problems.
Image Analyst
Image Analyst 2013년 12월 28일

0 개 추천

Remove the fplot call from the "if size(D,1)==1" block and that will probably solve it. It probably doesn't like it when you're calling fplot with just one point. lims is probably a one element vector in that case, and when it hits lims(1:2) it barfs.

댓글 수: 3

Image Analyst
Image Analyst 2013년 12월 28일
In the "else" block, I'd also take it out of the for loop and put it right after the "end" of the for loop.
Elia
Elia 2013년 12월 28일
i didn't understand exactly what do you mean ,where should i place the plot ? can you please show me howe the code will look like ? i tried without if-else loop (just for loop )i became the same problem too.
best regards sam
Image Analyst
Image Analyst 2013년 12월 28일
편집: Image Analyst 2013년 12월 28일
Xi and Ti are just single numbers, not arrays. You need to make them arrays, and then you don't need to have a special case for the first element:
D=cell2mat(get(handles.table,'data'));
for i=1:size(D,1)
T(i) = str2num(D(i,2));
X(i) = str2func(['@(t)' D(i,1)]);
end
fplot(Xi,Ti,'Parent',handles.axes1);
hold(handles.axes1, 'off')
grid on

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

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2013년 12월 27일

편집:

2013년 12월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by