### Translated by

このページのコンテンツは英語から自動翻訳されています。自動翻訳をオフにする場合は「<a class="turn_off_mt" href="#">ここ</a>」をクリックしてください。

## how to get element from matrix

ans sobhi

### ans sobhi (view profile)

さんによって質問されました 2019 年 2 月 18 日

さんによって 編集されました 2019 年 2 月 25 日
function btn_forward_Callback(hObject, eventdata, handles)
% hObject handle to btn_forward (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Th_1 = str2double(get(handles.Theta_1,'string'))*pi/180;
Th_2 = str2double(get(handles.Theta_2,'string'))*pi/180;
Th_3 = str2double(get(handles.Theta_3,'string'))*pi/180;
Th_4 = str2double(get(handles.Theta_4,'string'))*pi/180;
L_1 = 10;
L_2 = 20;
L_3 = 30;
L_4 = 10;
L(1) = Link([0 L_1 0 pi/2]);
L(2) = Link([0 0 L_2 0]);
L(3) = Link([0 0 L_3 0]);
L(4) = Link([0 0 L_4 0]);
Robot.name = 'anosh';
Robot.plot([Th_1 Th_2 Th_3 Th_4]);
T = Robot.fkine([Th_1 Th_2 Th_3 Th_4]);
handles.Pos_X.string = num2str(floor(T(1,4)));
function Pos_X_Callback(hObject, eventdata, handles)
there is error
Index exceeds matrix dimensions.
Error in ggg>btn_forward_Callback (line 188)
handles.Pos_X.string = num2str(floor(T(1,4)));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in ggg (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
Error while evaluating UIControl Callback.

ans sobhi

### ans sobhi (view profile)

2019 年 2 月 20 日
i solved it by this code
T = T.T;
set(handles.Pos_X,'string',T(1,4));
set(handles.Pos_Y,'string',T(2,4));
set(handles.Pos_Z,'string',T(3,4));
Geoff Hayes

### Geoff Hayes (view profile)

2019 年 2 月 20 日
you many want to rename the T in
T = Robot.fkine([Th_1 Th_2 Th_3 Th_4]);
to avoid confusion with the field that you are accessing of the same name.

2019 年 2 月 20 日
This suggests that T was not originally a matrix with 4 columns but instead, a structure. When you tried to get data from the 4th "column" of a structure, you got the error.

サインイン to comment.

R2017a

## 1 件の回答

2019 年 2 月 20 日

2019 年 2 月 25 日

Here's a summary of the comments under the question so that this question is marked as answered.
The variable "T" is a structure but was being accessed as if it were a matrix.
Here's a replication of the error
T.T1 = magic(4); % a 4x4 matrix stored in field 'T1' of structure "T"
T(1,4)
Index exceeds matrix dimensions. %matlab 2017b
Index in position 2 exceeds array bounds (must not exceed 1). %Matlab 2018a
Here's the solution
T.T1(1,4)
ans =
13

#### 0 件のコメント

サインイン to comment.

Translated by