I am receiving this error : Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more subscripts) is not supported.

When i try to run this code I'm receiving this error:
Subscripting a table using linear indexing (one subscript) or multidimensional indexing (three or more
subscripts) is not supported. Use a row subscript and a variable subscript.
a(1:11) %Imported data from excel
b(1:11) %Imported data from excel
c(1:11) %Imported data from excel
Resultant = sqrt(a*a + b*b + c*c);
Up = 180*atan2(a, sqrt(b*b + c*c))/pi;
Right = 180*atan2(b, sqrt(a*a + c*c))/pi;
while (0 < n < 11)
if (0 < Up || Right > 30)
disp('Fall is detected')
else
disp('No fall')
end
end

댓글 수: 2

The code you have showed us is incomplete
- There are no a, b anc c values defined/assigned.
- You have not initiated a loop counter nor is the loop counter updating according to conditions.
Sorry I did not get the 2nd point. Can you just show it with an example

댓글을 달려면 로그인하십시오.

 채택된 답변

a = readmatrix('a.xlsx');
b = readmatrix('b.xlsx');
c = readmatrix('c.xlsx');
%I have not suppressed the outcome so you can verify the values of a
%as the first value will be read as NaN (not a number)
a = a(2:11) %Imported data from excel
a = 1×10
-2.3000 -2.6000 -2.4000 -2.9000 -3.6000 2.9000 3.0000 3.6050 3.9800 2.0350
b = b(2:11); %Imported data from excel
c = c(2:11); %Imported data from excel
Resultant = sqrt(a.*a + b.*b + c.*c);
Up = 180*atan2(a, sqrt(b.*b + c.*c))/pi
Up = 1×10
-23.0245 -31.4445 -33.6392 -53.8149 -61.2833 51.4768 67.9266 53.7637 46.6764 33.7866
Right = 180*atan2(b, sqrt(a.*a + c.*c))/pi
Right = 1×10
-25.1592 -34.1804 -36.8788 -24.6751 -14.0999 -3.0929 -21.7576 -30.9710 -30.7839 -47.5465
%since there are 10 elements in the arrays, the index should go from 1-10
n = 1;
while (n < 11)
if (0 < Up(n) | Right(n) > 30)
disp('Fall is detected')
break %breaking the loop
else
disp('No fall')
end
n = n+1;
end
No fall No fall No fall No fall No fall
Fall is detected

댓글 수: 8

Can we run the same program for 1000 values just by changing the number from 10 to 1000
You can, but make sure your arrays have 1000 elements, otherwise it will give an error
How can I change the code if I want the "Fall is about to happen" when the value is above 0 and more than 30 and also less than 40, and want the the "Fall is detected" when the value is above 0 and more than 40 but not in between 30 to 40. Should I add if statement?
I am assuming we have to check both for Up and Right
%This is just simple comparison
%code
if (Up(n)>30 & Up(n)<40) | (Right(n)>30 & Right(n)<40)
disp('Fall is about to happen')
elseif Up(n)>40 | Right(n)>40
disp('Fall is detected')
end
%code
When I try to run this, I get values below 0 as well like -30,-40. So only I mentioned above 0
That should not be happening, if x>30 then it is automatically x>0
Is your data still the same?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Hi!
We don't import data from excel that way.
In your case better to use readmatrix:
A = readmatrix(yourFile.xlsx) ;
If you want to have the data as table use readtable:
tbl = readtable(yourFile.xlsx) ;
Hope this helps

댓글 수: 5

I tried it. It shows this error: Unrecognized variable name 'xlsx'.
Here is a demo based on your data:
a = readmatrix('a.xlsx') ;
b = readmatrix('b.xlsx') ;
c = readmatrix('c.xlsx') ;
a = a(2:11) ; %Imported data from excel
b = b(2:11) ; %Imported data from excel
c = c(2:11) ; %Imported data from excel
Resultant = sqrt(a.*a + b.*b + c.*c);
Up = 180*atan2(a, sqrt(b.*b + c.*c))/pi;
Right = 180*atan2(b, sqrt(a.*a + c.*c))/pi;
n = 0;
while ( n < 11)
if (0 < Up | Right > 30)
disp('Fall is detected')
else
disp('No fall')
end
n = n+1;
end
No fall No fall No fall No fall No fall No fall No fall No fall No fall No fall No fall
Note that the function readmatrix was first Introduced in R2019a. If you are using an older release MATLAB will throw an error. Consider to use dlmread instead.
Since you are looking to compare individual values, make this change
%replace
if (0 < Up | Right > 30)
%with
if (0 < Up(n) | Right(n) > 30)
and adjust the loop counter accordingly.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2022년 8월 23일

댓글:

2022년 8월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by