Filter löschen
Filter löschen

Trouble using findpeaks function

7 Ansichten (letzte 30 Tage)
Snow
Snow am 8 Jul. 2023
Beantwortet: Star Strider am 8 Jul. 2023
The attached data is a sinusodial wave. I want to find how many peaks are in this graph. In matlab, I click on the file and import thata data from both columns. I get the following error:
Error using findpeaks
Expected Y to be one of these types:
double, single
Instead its type was table.
Error in findpeaks>parse_inputs (line 199)
validateattributes(Yin,{'double','single'},{'nonempty','real','vector'},...
Error in findpeaks (line 135)
= parse_inputs(isInMATLAB,Yin,varargin{:});
So importing the data that way makes it a table.
Ok so i make a variable for each column and turned them into a 5464x1 matrix.
Im not sure what to do next in order to analyze the peaks. ANy help?

Antworten (1)

Star Strider
Star Strider am 8 Jul. 2023
I have no idea how you are importing them. The findpeaks function wants real vector data.
Try something like this —
T1 = readtable('run 4 vac to air volt.csv', 'VariableNamingRule','preserve')
T1 = 5464×2 table
Voltage, Ch A (V) Run #4 Voltage, Ch B (V) Run #4 ________________________ ________________________ -0.218 -9.412 -0.218 -9.413 -0.218 -9.413 -0.218 -9.412 -0.218 -9.412 -0.218 -9.413 -0.218 -9.413 -0.218 -9.413 -0.218 -9.412 -0.218 -9.413 -0.219 -9.413 -0.219 -9.413 -0.219 -9.413 -0.219 -9.413 -0.218 -9.412 -0.219 -9.413
ChA = T1{:,1};
ChB = T1{:,2};
[pksA,locsA] = findpeaks(ChA, 'MinPeakProminence',0.01);
[pksB,locsB] = findpeaks(ChB, 'MinPeakProminence',0.01);
figure
subplot(2,1,1)
plot(ChA)
hold on
plot(locsA,pksA, '+r')
hold off
hold on
hold off
subplot(2,1,2)
plot(ChB)
hold on
plot(locsB,pksB, '+r')
hold off
Note the use of curly braces {} to index into the table array.
Make appropriate changes to get the results you want.
.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by