My program works on MATLAB, but doesn't work on simulink. The error message says that Ph1 is empty. But it shouldn't be and is not empty on MATLAB. Can someone help me ?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hugo Jasinski
il 4 Dic 2021
Modificato: Alagu Sankar Esakkiappan
il 28 Gen 2022
function [M1, M2] = test_sortie(x, y, T, A)
tabtheta = zeros(1,length(T));
for i = 1:length(T) %on crée le tableau avec tous les angles correspondants aux séparations entre les bandes
tabtheta(i) = (pi/2 - atan2(y, T(i,1)-x))*180/pi;
end
Ph1 = [];
Ph2 = [];
[~, Ph2] = find(tabtheta>-3.04 & tabtheta<6.84); %On trouve tous les angles que les capteurs voient
[~, Ph1] = find(tabtheta>-6.84 & tabtheta<3.04);
Ph1calibre = zeros(1,length(Ph1)+2);
Ph2calibre = zeros(1,length(Ph2)+2);
for i = 2:(length(Ph1)+1)
Ph1calibre(i) = round(((tabtheta(Ph1(i-1))+3.8/2)/0.005) + 1975/2 + 1); %On calibre les bons angles
end
for i = 2:(length(Ph2)+1)
Ph2calibre(i) = round(((tabtheta(Ph2(i-1))-3.8/2)/0.005) + 1975/2 + 1); %On calibre les bons angles
end
Ph1calibre(1) = 1;
Ph1calibre(end) = 1976;
Ph2calibre(1) = 1;
Ph2calibre(end) = 1976;
Ph1 = [Ph1, Ph1(end)+1];
Ph2 = [Ph2, Ph2(end)+1];
M1 = 0;
M2 = 0;
for i = 1:length(Ph1)
M1 = M1 + T(Ph1(i),2)*A(Ph1calibre(i+1), Ph1calibre(i)); %calcul des moyennes
end
for i = 1:length(Ph2)
M2 = M2 + T(Ph2(i),2)*A(Ph2calibre(i+1), Ph2calibre(i));
end
end
This is my code. A is a 1976x1976 matrix, and T is a 78x2 matrix.
This program should return two averages, M1 and M2.
This is not my first program, I tried to modify it by iniatializing every variables and by using easier commands but I didn't success. Does someone have an idea of what's my problem ?
Here is the simulink code and the error message :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/823450/image.png)
An error occurred while running the simulation and the simulation was terminated
Caused by:
- Index exceeds matrix dimensions. The array Ph1 is empty and therefore has no valid indices. Error in 'simulinktest/MATLAB Function' (line 33) Ph1 = [Ph1, Ph1(end)+1]; Error in 'simulinktest/MATLAB Function' (line 33)
0 Commenti
Risposta accettata
Alagu Sankar Esakkiappan
il 7 Dic 2021
Modificato: Alagu Sankar Esakkiappan
il 28 Gen 2022
I gather that you are trying to use a MATLAB function to process inputs into two Averages. MATLAB function works the same on both MATLAB as well as Simulink platform. The empty Ph1 array problem may arise due to an unexpected data range in tabtheta i.e, No element in tabtheta satisfies conditions mentioned in Code for assignment to Ph1.
Sample MATLAB function call that results in the above problem:
test_sortie(40,300,ones(78,2),ones(1976,1976)) % Results in Ph1 & Ph2 becoming empty arrays
To find out the exact edge case for Failure, A possible way would be to try repeating the same function call for different values of x in a for loop in MATALB. For easier debugging, Try creating a Breakpoint on the line where error is caused in MATLAB.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su String 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!