I have 2 sets of noisy data when plotted against each other forms a parallelogram . I want to simplify this to a simple parallelogram with 4 vertices and find the area within.

1 view (last 30 days)
[T1, UAPP] = textread('Uapp.txt', '%f %f'); %load data into arrays
[T2, UC] = textread('uc.txt', '%f %f');
Error using textread
File not found.
C = 22*10.^-9;
F = 35*1000;
Q = C.*UC; % calculate Q
subplot(2,2,1); plot(UAPP, Q, 'R-'); title('Lissajous figure'); xlabel('UAPP'); ylabel('Charge (Q)');
max_UAPP = max(UAPP); %*efforts to find verticies*
max_Q = max(Q);
min_UAPP = min(UAPP);
min_Q = min(Q);
avg_UAPP = mean(UAPP);
avg_Q = mean(Q);
D = sqrt(((max_UAPP-avg_UAPP)^2)+((max_Q-avg_Q)^2));
pgon = polyshape([-8 -5 8 5], [-1 1 1 -1]);
subplot(2,2,2); plot(pgon);
POWER = S*F; %calculate power
I don't care much about plotting the parallelogram its just to help me visualise i tried to plot (pgon) with actual values from the graph but had many issues presumably because how small the values were, the current plot is a random unrelated test plot of a parralelogram. all i want to do is calulate the power, which is the area contained in the parralelogram by the frequency F. this should equal approximately 60 watts, any help is much appriciated, ive been stuck on this for over a week looking at different answers and trying various method before finally giving in and posting a question on it. Thank you.

Accepted Answer

Star Strider
Star Strider on 11 Nov 2022
It is first necessary to define the boundary and then use polyarea
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1188663/Uapp.txt');
T2 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1188668/Uc.txt');
x = T1{:,2};
y = T2{:,2};
% figure
% plot(x, y)
[k,v] = boundary(x,y,0.5);
ps = polyshape(x(k), y(k));
Warning: Polyshape has duplicate vertices, intersections, or other inconsistencies that may produce inaccurate or unexpected results. Input data has been modified to create a well-defined polyshape.
pwr = polyarea(x(k),y(k)) % Calculate Power
pwr = 9.9475e+04
[xc,yc] = centroid(ps);
figure
plot(x, y)
hold on
plot(xc, yc, 'p')
plot(x(k), y(k), 'r')
plot(ps)
hold off
grid
Use readtable or readmatrix rather than textread.
.

More Answers (1)

KSSV
KSSV on 11 Nov 2022
smooth the data and use polyarea.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!