Optimisation of X Y calculation code?

1 visualizzazione (ultimi 30 giorni)
Red Beard
Red Beard il 25 Ott 2012
Please help. The following is code from my application and is used to calculate the X value for a given Y value. I am having a problem because I need to repeat this process four times and before it is complete Matlab locks up and displays a message saying 'Windows system has run out of resources'. For this reason can anyone help optimise this process?
To explain: I have 456 data files containing 600 data readings (Y value) and their row numbers (X value). The difference of the Y values are passed through this process 4 times to calculate the X value for those points representing the maximum and minimum difference of the first 200 Y values, and then the maximum and minimum difference of the remaining Y values. This then loops until all of the data files have completed this process. My code below creates a plot each time as part of this calculation, and I assume that this is the reason why I run out of system resources, but I'm not sure how to improve the code? Any ideas?
% Calculates the equivalent X value for the Y value given.
x = dfxy(:,1,:);
y = dfxy(:,2,:);
yMinaxis = min(y);
yMaxaxis = max(y);
ylim([yMinaxis yMaxaxis]);
indexAtMax = find(y == dfymax1);
xAtMax = x(indexAtMax); % Sets xAtMax as the X value
close all;
xpointsymax1(i,:) = xAtMax; % Create array to hold all x points
All help is greatly appreciated.

Risposta accettata

Red Beard
Red Beard il 31 Ott 2012
Modificato: Red Beard il 31 Ott 2012
Ok, I worked out the solution to this problem, if anyone is interested it is as follows. This determines the X value for a given Y value, in this case the max and min of Y values. X = X values, Y = Y values.
Xsize = size(X);
% Sets Xsize to equal total number of X readings
Xreduced = Xsize - 200;
% Sets Xreduced to equal total number of readings minus 200.
[a,b]=max(Y(1:200));
% Calculates maximum value for Y points 1 to 200, and locates X point. a = maximum Y value, and b = X value.
[c,d]=max(Y(Xreduced:end));
% Calculates maximum value for Y points end-200 to end, and locates X point. c = maximum Y value, and b = X value.
[e,f]=min(Y(1:200));
% Calculates minimum values for points 1 to 200, and locates X point. e = minimum Y value, and b = X value.
[g,h]=min(Y(Xreduced:end));
% Calculates minimum value for Y points end-200 to end, and locates X point. g = minimum Y value, and h = X value.
dXsize = d + Xsize - 200;
% Adds the remaining points to the minimum X value to give the position of X over the total of all data points.
hXsize = h + Xsize - 200;
% Adds the remaining points to the minimum X value to give the position of X over the total of all data points.
All the best!
Redbeard.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by