Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Reversing the y-value of a multiple files

Subject: Reversing the y-value of a multiple files

From: Samuel

Date: 9 Jun, 2012 03:04:23

Message: 1 of 2

Hello,

I'm new to matlab and I'm trying to reverse the y-values on multiple files without success. Here's what I'm trying to do right now:
------------------------------------------------------------------------------------------------------------------------
function i2m_reverseyaxis

%This function will reverse the y-axis of the trial_x and trial_y

%Select a folder containing zoo files
fld = uigetfolder;
cd(fld);

if strcmp(computer,'PCWIN64')
    fl = engine('path',fld,'extension','zoo','sub','yes');
else
    fl = engine('path',fld,'extension','zoo');
end

for i= 1:length(fl)

fname = fl{i};

t = load(fname,'-mat');
data = t.data;


if ~isempty(strfind(fname,'_x_'))
     set(gca,'yDir','reverse');
    
    
elseif ~isempty(strfind(fname,'_y_'))
     set(gca,'yDir','reverse');
    

else
    disp('nothing')
end
% save all the modifications
save (fname,'data');
end
----------------------------------------------------------------------------------------------------------------------
Basically, my values on the y-axis are from 180 to -180 and I want to reverse the y-values (to get a mirror of my plot). Could anyone help me please. Thank you in advance for your help.

Subject: Reversing the y-value of a multiple files

From: dpb

Date: 9 Jun, 2012 18:31:27

Message: 2 of 2

On 6/8/2012 10:04 PM, Samuel wrote:
> Hello,
> I'm new to matlab and I'm trying to reverse the y-values on multiple
> files without success. Here's what I'm trying to do right now:
> ------------------------------------------------------------------------------------------------------------------------
>
> function i2m_reverseyaxis
> %This function will reverse the y-axis of the trial_x and trial_y
> %Select a folder containing zoo files
> fld = uigetfolder;
> cd(fld);
>
> if strcmp(computer,'PCWIN64')
> fl = engine('path',fld,'extension','zoo','sub','yes');
> else
> fl = engine('path',fld,'extension','zoo');
> end

Is engine() something like dir()???

> for i= 1:length(fl)
> fname = fl{i};
> t = load(fname,'-mat');
> data = t.data;
> if ~isempty(strfind(fname,'_x_'))
> set(gca,'yDir','reverse');
> elseif ~isempty(strfind(fname,'_y_'))
> set(gca,'yDir','reverse');
> else
> disp('nothing')
> end
> % save all the modifications
> save (fname,'data');
> end
...

> Basically, my values on the y-axis are from 180 to -180 and I want to
> reverse the y-values (to get a mirror of my plot). Could anyone help me
> please. Thank you in advance for your help.

I don't see any plot() commands for gca() to reference.

I don't think you need the isempty() in the if clauses, but it doesn't
hurt anything.

What seems to be not working? Looks like as long as your file names are
correct and match the naming convention you're testing for it ought to
swap the axis direction.

It isn't going to have any effect on the data on disk, however, only on
the plot as shown.

If you really intend to reverse the y data storage order, then you don't
need to fiddle w/ the plot axis direction, just do

fliplr() or flipud() on the y-vector before plotting.

--

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us