matlab determine a curve

11 次查看(过去 30 天)
joo
joo 2012-9-16
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
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
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 个评论
joo
joo 2012-9-18
and why do you Calculate distance from (50,360) of every point? thank you very much!
Image Analyst
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
joo 2012-9-19
编辑:joo 2012-9-19
image analyst i am sorry to insist but i have been working all these days in this and still i can't understand. i see that in the plot you can vizualize (50,360). but why are these numbers and not for example (55,365)-with this pair the results would be different... i really don't understand where do they come from since i investigated all the results and code and nothing related with (50,360)... i am stucked in this for days. i am so grateful for your help. this is very important for me. thank you so much for your attention.
  8 个评论
joo
joo 2012-10-5
in your code you filter x,y data responsible for the noise/small peaks. you discover this peaks by x^2 +y^2. how can you justify this? shouldn't the noise data be seen only in x and y data alone? how can i justify this filtering?
i am not at all declining your code... i just need to justify the steps, and this is a doubt of mine... can you clear me this last doubt? thank you very much.
Image Analyst
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 CenterFile Exchange 中查找有关 Get Started with MuPAD 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by