基本的に上記と同じです。guidata(hObject、handles)とhandles = guidata(hObject)の違いは何ですか?
私のMATLAB GUIには、テキストボックスからデータを取得し、それを配列ハンドル(より具体的には複数のウェイポイント)に保存するプッシュボタンがあります。私は後の段階でこの行列を使用しているので、ハンドルに格納されたデータが必要です。
コールバック関数では、これを行う別の関数を呼び出しています(メインファイルをきれいに整えておくため)。ここでは、対応するハンドルにすべてのデータを保存した後、guidata(hObject, handles)
に電話して変更を保存します。
しかし、コールバックでは、display(handle.data)
を呼び出すたびに、私はコールバックを呼び出す前にハンドルを表示しますが、私はそれをリフレッシュしました。今すぐ別のguidata(hObject, handles)
をコールバックで直接呼び出しても何も変わりませんが、handles = guidata(hObject)
を呼び出すと動作します。
私の質問:なぜですか? MATLABですか?
CODE:
func_addWaypoint(hObject, handles)
display(handles.cart_coords)
handles = guidata(hObject);
display(handles.free_coords)
注:最初のdisplay()
は、私に古いデータを与える第二は、私に新しいデータを提供します。 handles
あなたの変数の2つのコピーが実際にあります
function func_addWaypoint(hObject,handles)
new_waypoint = nan(3,2);
coord_constraint = ones(3,2);
new_waypoint(1,1) = str2double(handles.edit_start_x1.String);
new_waypoint(2,1) = str2double(handles.edit_start_x2.String);
new_waypoint(3,1) = str2double(handles.edit_start_x3.String);
new_waypoint(1,2) = str2double(handles.edit_stop_x1.String);
new_waypoint(2,2) = str2double(handles.edit_stop_x2.String);
new_waypoint(3,2) = str2double(handles.edit_stop_x3.String);
v
for i = 1:numel(new_waypoint)
if isnan(new_waypoint(i))
new_waypoint(i) = rand() * 2 - 1;
coord_constraint(i) = 0;
end
end
handles.cart_coords = [handles.cart_coords, new_waypoint];
handles.free_coords = [handles.free_coords, coord_constraint];
guidata(hObject, handles);