Filtering the values of current and voltages based on a criteria

I have a list of 1000000 sets of data in a .mat file. it has 5 columns, say A,B,C, Current and voltage. for many sets of data we would be having same current and voltages values. I need to read the file and then I need to filter out and get the values of current and voltage as output based on some condition. How do i do it ? I'm new to matlab. kindly help
The data looks something like this
A B C current voltage
.1 0.33 .99 1 1
0.2 0.34 .100 1 2
0.3 0.35 .101 1 3
0.4 0.36 .102 1 1
0.5 0.37 .103 2 3
0.6 0.38 .104 2 6
0.7 0.39 .105 2 8
0.8 0.40 .106 3 3
0.9 0.41 .107 3.5 3
0.10 0.42 .108 3 3.5
0.11 0.43 .109 3 0
0.12 0.44 .110 3 3.5
0.13 0.45 .111 3.5 0
0.14 0.46 .112 3.5 6
0.15 0.47 .113 3.5 7
How do i print the values of current and voltage by reading each data based on some condition ( condition is not related to current or voltage ) .The condition is with respect to time, and not A,B, C
PS: reading the file is done, I'm getting the proper output. only filtering part is left

回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 3 月 12 日

0 投票

Suppose you have two linear arrays named current and voltage, you can filter them based on a condition as follow.
mask = current > voltage;
current = current(mask);
voltage = voltage(mask);
It filters all values where current is greater than voltage.

14 件のコメント

Ganesh Kini
Ganesh Kini 2020 年 3 月 12 日
Hi Ameer Hamza, Thanks for the suggestion. But it not the case
A B C current Voltage
.1 0.33 .99 1 1
0.2 0.34 .100 1 2
0.3 0.35 .101 1 3
0.4 0.36 .102 1 1
0.5 0.37 .103 2 3
0.6 0.38 .104 2 6
0.7 0.39 .105 2 8
0.8 0.40 .106 3 3
0.9 0.41 .107 3.5 3
0.10 0.42 .108 3 3.5
0.11 0.43 .109 3 0
0.12 0.44 .110 3 3.5
0.13 0.45 .111 3.5 0
0.14 0.46 .112 3.5 6
0.15 0.47 .113 3.5 7
I have to get the value of the current and voltages by reading the data of A,B,C based on the some condition and that condition is not with respect to current or the voltage
Walter Roberson
Walter Roberson 2020 年 3 月 12 日
mask = A >= 0.5 & C <= 0.111;
current(mask)
voltage(mask)
Construct whatever combination condition is appropriate for your situation.
Ganesh Kini
Ganesh Kini 2020 年 3 月 12 日
Hi Walter,
thanks for the edit and suugestion.
The condition is with respect to time, and not A,B, C
Ameer Hamza
Ameer Hamza 2020 年 3 月 13 日
Ganesh, can you give us a small example. For example, consider this samll matrix
A = [0.1 0.33 .99 1 1;
0.2 0.34 .100 1 2;
0.3 0.35 .101 1 3;
0.4 0.36 .102 1 1;
0.5 0.37 .103 2 3;
0.6 0.38 .104 2 6];
Give an example of the condition and what is your expected output?
Ganesh Kini
Ganesh Kini 2020 年 3 月 13 日
Hi Ameer,
The condition is w.r.t time
A B C current voltage time
.1 0.33 .99 1 1 1ns
0.2 0.34 .100 1 2 1ns
0.3 0.35 .101 1 3 1ns
0.4 0.36 .102 1 1 2ns
0.5 0.37 .103 2 3 2ns
0.6 0.38 .104 2 6 1ns
0.7 0.39 .105 2 8 3ns
0.8 0.40 .106 3 3 3ns
0.9 0.41 .107 3.5 3 3ns
if i choose 1ns as the condition for time
The output should look like
Current = 1, 2
Voltage = 1,2,3,6.
Ameer Hamza
Ameer Hamza 2020 年 3 月 13 日
If you have variables named time, current, and voltage than try
mask = time==1;
current_filtered = unique(current(mask,:));
voltage_filtered = unique(voltage(mask,:));
Ganesh Kini
Ganesh Kini 2020 年 3 月 22 日
Hi,
Suppose i have the data in a .mat file how do you extract ?
s ='results.mat';
load(s)
Then do you think the above code will work ??
kindly let me know and help me
Walter Roberson
Walter Roberson 2020 年 3 月 22 日
s ='results.mat';
s_struct = load(s);
current = s_struct.current;
voltage = s_struct.voltage;
Ganesh Kini
Ganesh Kini 2020 年 4 月 3 日
Thanks,
I guess it wont filter based on the time.
if i need to filter it based on time. how can i do it ?
Please suggest
Ameer Hamza
Ameer Hamza 2020 年 4 月 3 日
Which is the time column in you matrix and how do you want to filter it?
Ganesh Kini
Ganesh Kini 2020 年 4 月 3 日
yes, based on the time i want to get all current and voltage values
Filtering for 100000 datas
Ameer Hamza
Ameer Hamza 2020 年 4 月 3 日
But which variable is time?
Ganesh Kini
Ganesh Kini 2020 年 4 月 3 日
A BC current voltage time
.1 0.33 .99 1 1 1ns
0.2 0.34 .100 1 2 1ns
0.3 0.35 .101 1 3 1ns
0.4 0.36 .102 1 1 2ns
0.5 0.37 .103 2 3 2ns
0.6 0.38 .104 2 6 1ns
0.7 0.39 .105 2 8 3ns
0.8 0.40 .106 3 3 3ns
0.9 0.41 .107 3.5 3 3ns
This an example how it looks. So for time 1 ns i want all the values of current and voltage
but the above matrix is stored in a .mat file.
I need to access the variables by loading the file and then extracting the current and voltage value based on time = 1ns condition
Please let me know
Ameer Hamza
Ameer Hamza 2020 年 4 月 3 日
load('filename.mat'); % write your filename
mask = time == 1;
filtered_current = current(mask);
filtered_voltage = voltage(mask);

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

カテゴリ

タグ

質問済み:

2020 年 3 月 12 日

コメント済み:

2020 年 4 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by