フィルターのクリア

Finding indices of certain numbers from simulation data

7 ビュー (過去 30 日間)
Abhinav Aravind
Abhinav Aravind 2023 年 3 月 1 日
コメント済み: Abhinav Aravind 2023 年 3 月 8 日
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 件のコメント
Mathieu NOE
Mathieu NOE 2023 年 3 月 1 日
hello
please share your data (as mat file) and explain which data (indexes) you are looking for
Askic V
Askic V 2023 年 3 月 5 日
編集済み: Askic V 2023 年 3 月 6 日
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]
x = 1×6
1.0000 0.3333 0.7500 0.8000 1.0000 1.1000
[c, i] = find(x==0.333333333333333)
c = 1×0 empty double row vector i = 1×0 empty double row vector

サインインしてコメントする。

回答 (2 件)

Akira Agata
Akira Agata 2023 年 3 月 6 日
How about using ismembertol function?
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
idx = 1×6 logical array
0 1 0 0 0 0
x(idx)
ans = 0.3333
  1 件のコメント
Abhinav Aravind
Abhinav Aravind 2023 年 3 月 8 日
Thank you Akira for the suggestion.
I tried this method. Although the required number shows up, I am unable to find the index of that number. Perhaps, could you suggest a way of finding the index of that as well ?
Thank you once again

サインインしてコメントする。


Sarvesh Kale
Sarvesh Kale 2023 年 3 月 6 日
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
n = 1×11
1 2 3 4 5 6 7 8 9 10 11
key = 2 ;
idx = x == key % comparision to search your number
idx = 1×11 logical array
0 0 0 1 1 0 0 0 0 0 0
n(idx) % this will give you index
ans = 1×2
4 5
I hope this helps
Thank you
  1 件のコメント
Abhinav Aravind
Abhinav Aravind 2023 年 3 月 8 日
Thank you very much for the suggestion, Sarvesh Kale. I tried this method, it works fine with integers but not with float values.
The array generated from the simulation does not contain pure integers, but decimal values.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by