Finding indices of certain numbers from simulation data
Afficher commentaires plus anciens
Hello all,
I want to find out the index values of certain numbers from an array dataset obtained from a Simulink simulation. The simulation results are stored in the workspace as an array. I am logging it to the workspace using a scope.
I tried using the find() command to find the index values, but it just returned an empty vector. I even tried using ismember() to return 0 or 1 based on whether a number belongs to that simulation data, but that also returned an empty vector.
The find() command works fine when using it on arrays imported from excel sheet.
I am not sure what I am doing wrong. Any suggestions or advice would be of great help. Thank you very much in advance.
Edit: I have attached the simulation file
3 commentaires
Pratheek
le 1 Mar 2023
Can you share the .slx file(simulation file) where you are facing the issue.
Mathieu NOE
le 1 Mar 2023
hello
please share your data (as mat file) and explain which data (indexes) you are looking for
Is it possible that array is of type double (all elements are double) and you try to use the function find to find this specific number?
It is very hard to use "equal" with double numbers because there is no infinite precision
x = [1, 1/3, 3/4, 4/5, 1, 1.1]
[c, i] = find(x==0.333333333333333)
Réponses (2)
The following is an example:
x = [1, 1/3, 3/4, 4/5, 1, 1.1];
idx = ismembertol(x, 0.33, 0.01); % find 0.33±max(x)*0.01
idx
x(idx)
1 commentaire
Abhinav Aravind
le 8 Mar 2023
Suppose your logged data is x in workspace then to find index of a certain number in that you can do the following
x=[1,1,1,2,2,3,3,4,5,5,5];
n=1:length(x) % generate index vector
key = 2 ;
idx = x == key % comparision to search your number
n(idx) % this will give you index
I hope this helps
Thank you
1 commentaire
Abhinav Aravind
le 8 Mar 2023
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!