error: Index exceeds matrix dimensions
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
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
2013 年 12 月 27 日
Try the squeeze() command, sometimes non functional extra dimensions are created which give these kinds of problems.
Image Analyst
2013 年 12 月 28 日
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
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
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!