Azzera filtri
Azzera filtri

How to fix the following errors

4 visualizzazioni (ultimi 30 giorni)
Matthew Backert
Matthew Backert il 22 Feb 2018
Risposto: Bhuvnesh Singh il 26 Feb 2018
I am receiving these two errors and don't entirely know how to fix them. The first is because my array starts at zero but I can't figure out to fix the rest of my code to mimic that. The other error I just have no clue. ANy help would be very appreciated.
Subscript indices must either be real positive integers or logicals.
Error in Lab3_2 (line 8) p(h)=po(1+(-6.5*10^(-3)/To)*(h-1)).^(-(go/(-6.5*10^(-3)*R)));
  1 Commento
Torsten
Torsten il 22 Feb 2018
You can't use symbolic variables as loop indices.
Use the numerical values instead.

Accedi per commentare.

Risposte (1)

Bhuvnesh Singh
Bhuvnesh Singh il 26 Feb 2018
This error occurs when you attempt to index into an array using indices that are not positive integers or logical values. Here are some tips for common situations that cause this error message:
1) Double check that your indices are positive integers. Indices in MATLAB cannot be 0, and by default, start with 1.
2) If you use floating-point arithmetic to compute an index array, then the array values may not be exact integers. The 'round' function is handy when you know you have an index value that is nearly the integer index that you want. For example,
A = [1 2 3 4; 5 6 7 8];
ind_float = 2.00001;
ind_int = round(ind_float);
A(ind_float)
Below is a way to check if an index array 'ind'' contains exact integer values. This command returns a 'logical' array, where 1 indicates the index value is an exact integer, and 0 indicates it is not.
ind == round(ind)
3) If you assign a variable to the same name as a built-in function in MATLAB, then you will overwrite that function and encounter the error when you attempt to call it. For example,
max = rand(5);
A = rand(5);
max(A)
In this event, rename your variable and clear the old one to proceed:
B = max;
clear max max(A)
For more information on indexing in MATLAB, see the following documentation page: https://www.mathworks.com/help/matlab/math/matrix-indexing.html

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by