matlab determine a curve
2 次查看(过去 30 天)
显示 更早的评论
Imagine i have an original plot with superimposed '8' shape curves (the curves are all different but similar to the '8' shape). Does anyone know how to obtain a mean curve having a matrix with the correspondent x,y points from the original plot? I mean, I pretend a medium single curve.
Any code or just ideas would be very very helpful for me. Thank you very very much!
7 个评论
Image Analyst
2012-9-18
Can you post your code where you use xlsread to read it in and loop over each curve to find the left-most part and record its row? And your code to use circshift to align them? Can you do any of that to help us help you?
采纳的回答
Image Analyst
2012-9-18
编辑:Image Analyst
2012-9-18
You have a little noise on your y-data, as you can see from this example code. You might need to smooth that out first.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
folder = 'C:\Users\joo\Documents\Temporary';
fullFileName = fullfile(folder, 'livro1.xlsx');
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
[num txt raw] = xlsread(fullFileName);
x = num(:, 1);
y = num(:, 2);
% Plot x
subplot(2,2,1);
plot(x, 'b-');
xlabel('Element Number', 'FontSize', fontSize);
ylabel('X', 'FontSize', fontSize);
title('X', 'FontSize', fontSize);
grid on;
% Plot y
subplot(2,2,2);
plot(y, 'b-');
xlabel('Element Number', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Y', 'FontSize', fontSize);
grid on;
% Plot curves
subplot(2,2,3);
plot(num(:, 1), num(:, 2), 'b-');
title('X', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
grid on;
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Calculate distance from (50,360) of every point.
distances = sqrt((x - 50).^2 - (y - 360).^2)
subplot(2,2,4);
plot(distances, 'b-');
title('Distance from (50, 360)', 'FontSize', fontSize);
xlabel('index', 'FontSize', fontSize);
ylabel('Distances', 'FontSize', fontSize);
grid on;
% Find valleys in distances to find out where it turned around.
[valleys, indexesAtMins] = findpeaks(-distances)
% Plot them.
hold on;
plot(indexesAtMins, -valleys, 'r*');
4 个评论
Image Analyst
2012-9-18
I just answered that. Run my code and look at the graph and I think you'll see why.
更多回答(1 个)
joo
2012-9-19
编辑:joo
2012-9-19
8 个评论
Image Analyst
2012-10-5
I'm calculating the Euclidean distance from some point way off the end of the curve's travel to the points on the curve using the Pythagorean Theorem, which is the sqrt of the sum of the squares. That distance oscillates as the point on the curve gets closer and farther away from the fixed, distant point as the curve point travels.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with MuPAD 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!