I need to verify efficiency of my current code.
Show older comments
I have written code for my MATLAB program but I know it's not an efficient code because the number of variables for my program needs to be very high because of the large data set. So I have a cell for all my data: the first column of the cell contains all "x" matrices for each point in the data set and the second column contains all "y" matrices.
Now, for the "x" matrices: I need to work with each matrix under "x" in order to "sort" them, "print" the minimum value for the first point in all "x" matrices" (with corresponding "y" values), then "print" the second value of the minimum all second data points of "x" with the corresponding "y" values, till as many as 20,000 data points for some of the matrices. Before these sorting functions, I have to scale the data, and such.
How do I go about doing that?
So far, all I have done is applying "cell2mat" to my cell array and working individually with the data points, then applying a combination of "for" and "if" loops to get my required output. But this process seems to be to be very inefficient and I don't know where to look to understand the way of making them efficient.
Any ideas?
2 Comments
Jan
on 23 Jun 2015
It is impossible to suggest improvements based on a rough description of the code as text. Please post the relevant part of the code with meaningful test data, such that the readers can run it by copy&paste. And please add this important information to the original question, where the readers expect them - not as comment.
Prakriti Sardana
on 23 Jun 2015
Answers (1)
Walter Roberson
on 23 Jun 2015
For each matrix of x,
[sortedx, sortorder] = sort(x, 'stable');
and then
reorderedy = y(sortorder);
Sorting on column K of x would be
[sortedxk, sortorder] = sort(x(:,k), 'stable');
reorderedx = x(sortorder, :);
reorderedy = y(sortorder, :);
Now you can iterate through as they are all in respective order.
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!