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:
Copying "i" to a new variable after load

Subject: Copying "i" to a new variable after load

From: Virginia Silva

Date: 5 Dec, 2008 17:02:02

Message: 1 of 5

Hi!

This is my first posting here because I couldn't find any answer through the internet... sorry for my english because it's not my native language, well here it goes

I have a mat file with a certain matrix called "i" which in my case is 50x1 with doubles in it. It happens that I load this file inside my function like this and I do the following:

function [] = hola()
  load tabla_Phi.mat
  io=i;
end

If I do this, io gives me io=0 + 1.0000i !!!!!!!!!!!!!!!!!!!!!! a complex number!!

If I create a break point in the line io=i; and in the command window I type io=i; io will come out ok, but if I press F10 for another step the result comes out wrong, I tried this without the load and creating a vector "i" and this doesn't happen so it might be a problem with the combination between load and "i". This is so weird, it took me a long time to create the "i" vector so I really need to solve this problem, hope anyone can help me.

Thanks
Virginia

Subject: Copying "i" to a new variable after load

From: Joerg Buchholz

Date: 5 Dec, 2008 17:37:01

Message: 2 of 5

"Virginia Silva" <virginiasilvamunoz@gmail.com> wrote in message <ghbmqa$48u$1@fred.mathworks.com>...
> Hi!
>
> This is my first posting here because I couldn't find any answer through the internet... sorry for my english because it's not my native language, well here it goes
>
> I have a mat file with a certain matrix called "i" which in my case is 50x1 with doubles in it. It happens that I load this file inside my function like this and I do the following:
>
> function [] = hola()
> load tabla_Phi.mat
> io=i;
> end
>
> If I do this, io gives me io=0 + 1.0000i !!!!!!!!!!!!!!!!!!!!!! a complex number!!
>
> If I create a break point in the line io=i; and in the command window I type io=i; io will come out ok, but if I press F10 for another step the result comes out wrong, I tried this without the load and creating a vector "i" and this doesn't happen so it might be a problem with the combination between load and "i". This is so weird, it took me a long time to create the "i" vector so I really need to solve this problem, hope anyone can help me.
>
> Thanks
> Virginia

This could be a workaround:

function [] = hola()
i = [];
load tabla_Phi.mat
io=i;
end

Subject: Copying "i" to a new variable after load

From: Image Analyst

Date: 5 Dec, 2008 17:39:02

Message: 3 of 5

"Virginia Silva" <virginiasilvamunoz@gmail.com> wrote in message <ghbmqa$48u$1@fred.mathworks.com>...
> Hi!
>
> This is my first posting here because I couldn't find any answer through the internet... sorry for my english because it's not my native language, well here it goes
>
> I have a mat file with a certain matrix called "i" which in my case is 50x1 with doubles in it. It happens that I load this file inside my function like this and I do the following:
>
> function [] = hola()
> load tabla_Phi.mat
> io=i;
> end
>
> If I do this, io gives me io=0 + 1.0000i !!!!!!!!!!!!!!!!!!!!!! a complex number!!
>
> If I create a break point in the line io=i; and in the command window I type io=i; io will come out ok, but if I press F10 for another step the result comes out wrong, I tried this without the load and creating a vector "i" and this doesn't happen so it might be a problem with the combination between load and "i". This is so weird, it took me a long time to create the "i" vector so I really need to solve this problem, hope anyone can help me.
>
> Thanks
> Virginia
--------------------------------------------------------------
Virginia:
Give this a try:

storedValues = load('tabla_Phi.mat'); % Read all stored values into a structure.
io = storedValues.i; % Assign just the "i" variable of the structure to the "io" variable.

See if that works.
In general, it's not recommended to use i as a variable name for precisely the reason you experienced.

Regards,
ImageAnalyst

Subject: Copying "i" to a new variable after load

From: Virginia Silva

Date: 5 Dec, 2008 17:54:04

Message: 4 of 5

Thank you both!

Now it's working...

I used "i" only because I wanted to follow the notation from my reference, but it looks like this wasn't a very good idea, anyway thanks!

Virginia

Subject: Copying "i" to a new variable after load

From: Steven Lord

Date: 5 Dec, 2008 18:42:42

Message: 5 of 5


"Virginia Silva" <virginiasilvamunoz@gmail.com> wrote in message
news:ghbmqa$48u$1@fred.mathworks.com...
> Hi!
>
> This is my first posting here because I couldn't find any answer through
> the internet... sorry for my english because it's not my native language,
> well here it goes
>
> I have a mat file with a certain matrix called "i" which in my case is
> 50x1 with doubles in it. It happens that I load this file inside my
> function like this and I do the following:
>
> function [] = hola()
> load tabla_Phi.mat
> io=i;
> end
>
> If I do this, io gives me io=0 + 1.0000i !!!!!!!!!!!!!!!!!!!!!! a complex
> number!!

Yes, that's expected behavior. Read this document from the support website:

http://www.mathworks.com/support/solutions/data/1-166JL.html?solution=1-166JL

> If I create a break point in the line io=i; and in the command window I
> type io=i; io will come out ok, but if I press F10 for another step the
> result comes out wrong, I tried this without the load and creating a
> vector "i" and this doesn't happen so it might be a problem with the
> combination between load and "i". This is so weird, it took me a long time
> to create the "i" vector so I really need to solve this problem, hope
> anyone can help me.

Joerg and ImageAnalyst gave you two suggestions; I'd personally use
ImageAnalyst's solution, as it scales better with the number of variables in
your MAT-file.

--
Steve Lord
slord@mathworks.com

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