0

私は初心者です。質問したいのですが、編集テキストをマトリックスに入れる方法は? x(1,1)たとえば、0 から 1 の数字で塗りつぶされる 30 個の編集テキストがありますx(1,30)。編集テキストの入力から、行列を作成したいと考えています。

私はこのコードを試しました:

function edit1_Callback(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double

x(1, 1) = str2double(get(hObject,'string'))

まで....

function edit30_Callback(hObject, eventdata, handles)

% hObject handle to edit30 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit30 as text
% str2double(get(hObject,'String')) returns contents of edit30 as a double

x(1, 30) = str2double(get(hObject,'string'))

しかし、コマンドウィンドウは次のように表示されます...

x =

     1

x =

     0 0

x =

     0 0 0

x =

         0 0 0 0.2500

x =

         0 0 0 0 0.5000

x =

     0 0 0 0 0 0

しかし、実際には、結果が次のようにマトリックスになりたい

1 0 0 0.25 0.5 0

この問題を解決する方法を知っている人はいますか?

4

1 に答える 1

0

あなたの問題は関数のスコープです。各コールバック関数はx独自のスコープで定義されるため、関数が終了すると(xコンソールに値を表示)、xはなくなります。

1つの方法は、構造体xを使用して関数間で変数を渡すことです。の代わりにhandles使用してください。GUIの初期化と同様に、このマトリックスを初期化することもお勧めします。handles.xxhandles.x = zeros(1,30);

于 2012-03-05T04:13:46.770 に答える