フィルターのクリア

()-indexing must appear last in an index expression What is my mistake? method gauss jordan gui

3 ビュー (過去 30 日間)
function pushbutton6_Callback(hObject, eventdata, handles)
set(handles.pushbutton1, 'value');
u=1;
set(handles.pushbutton3, 'value');
u=2
set(handles.pushbutton4, 'value');
u=3
switch u
case 1
m=[str2double(get(handles.edit3,'string')) str2double(get(handles.edit4,'string'))(str2double(get(handles.edit9,'string'))); str2double(get(handles.edit10,'string')) str2double(get(handles.edit11,'string')) str2double(get(handles.edit15,'string'))];
case 2
m=[str2double(get(handles.edit3,'string')) str2double(get(handles.edit4,'string')) str2double(get(handles.edit6,'string')) (str2double(get(handles.edit9,'string'))); str2double(get(handles.edit10,'string')) str2double(get(handles.edit11,'string')) str2double(get(handles.edit12,'string')) (str2double(get(handles.edit15,'string'))); str2double(get(handles.edit16,'string')) str2double(get(handles.edit17,'string')) str2double(get(handles.edit18,'string')) str2double(get(handles.edit21,'string')) ];
case 3
case 4
otherwise
x=0
end
if all(size(m)==[2,3])
h=1
else
if all(size(m)==[3,4])
h=2
else
if all(size(m)==[4,5])
h=3
else
if all(size(m)==[5,6])
h=4
end
end
end
end
switch h
case 1
m(1,:)=m(1,:)/m(1,1);
m(2,:)=m(2,:)-(m(2,1))*(m(1,:));
m(2,:)=m(2,:)/m(2,2);
m(1,:)=m(1,:)-(m(1,2))*(m(2,:));
x1=m(1,3)
x2=m(2,3)
set(handles.edit35,'string',x1);
set(handles.edit36,'string',x2);
case 2
m(1,:)=m(1,:)/m(1,1);
m(2,:)=m(2,:)-(m(2,1))*(m(1,:));
m(3,:)=m(3,:)-(m(3,1))*(m(1,:));
m(2,:)=m(2,:)/m(2,2);
m(3,:)=m(3,:)-(m(3,2))*(m(2,:));
m(3,:)=m(3,:)/m(3,3);
m(2,:)=m(2,:)-(m(2,3))*(m(3,:));
m(1,:)=m(1,:)-(m(1,3))*(m(3,:));
m(1,:)=m(1,:)-(m(1,2))*(m(2,:));
x1=m(1,4)
x2=m(2,4)
x3=m(3,4)
set(handles.edit35,'string',x1);
set(handles.edit36,'string',x2);
set(handles.edit37,'string',x3);
case 3
x=3
case 4
x=2
otherwise
x=32
end
matlab says that this is my mistake
m=[str2double(get(handles.edit3,'string')) str2double(get(handles.edit4,'string'))(str2double(get(handles.edit9,'string'))); str2double(get(handles.edit10,'string')) str2double(get(handles.edit11,'string')) str2double(get(handles.edit15,'string'))];

採用された回答

OCDER
OCDER 2017 年 11 月 3 日
You can't do the following:
str2double(get(handles.edit4,'string'))(str2double(get(handles.edit9,'string')));
Did you mean to add a space between the terms? If not and you want to access the nth index of this variable, keep reading.
Unlike other languages like JAVA, you can't immediately take the output of str2double and find the value at the nth index. You need to use a temporary variable to do this kind of indexing. See this example:
a = {'1' '2' '3'}
b = '2'
c = str2double(a)(str2double(b)) % Error: ()-indexing must appear last in an index expression.
temp = str2double(a);
c = temp(str2double(b)); %no error. this works.
In your case, any string that will return a matrix should be stored in a temporary matrix.
temp = str2double(get(handles.edit4,'string'))
value = tempMat(str2double(get(handles.edit9,'string')));
If you have to extract a value using 2 edit text boxes frequently, consider making a simple function like this:
function Value = getValue(Handle1, Handle2)
Values = str2double(get(Handle1, 'string'));
Value = Values(str2double(get(Handle2, 'string')));
And whenever you want to get a value from a edit text box based on the index value of another text box, do this:
getValue(handles.edit4, handles.edit9)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by