From: Zaki Shirwani on
Sorry, I thought you just wanted to read the value from workspace varfiable.
If you want to both read and write, try this:

%%%
function y = fcn()
eml.extrinsic('evalin');
y = 0; % You need this to set the type of 'y'
evalin('base','x = x*2');
y = evalin('base','x')
%%%

Further reference:
http://www.mathworks.com/access/helpdesk/help/toolbox/eml/ug/bq1h2z8-34.html#bq1h2z9-46

HTH.

"Ryan Osborn" <ryan.osborn88(a)gmail.com> wrote in message
news:htjjut$9oc$1(a)fred.mathworks.com...
> "Zaki Shirwani" <shirwani(a)mathworks.com> wrote in message
> <htj8rt$iiv$1(a)fred.mathworks.com>...
>> You will if it's a tunable parameter. There's a "Tunable" checkbox that
>> shows up in the "Ports and Data Manager" when you change the data scope
>> to "Parameter". If it's checked (default) you can change the value of
>> the parameter in MATLAB workspace and it will be picked up without
>> causing code regeneration. However, if you change the
>> type/size/complexity of the variable that will cause code to regenerate.
>
> I did a simple test, I set x=2 in the workspace, then passed x to my
> embedded matlab function as a tunable parameter. In the code I then did
> x=x*2, but when I look in the workspace it has not changed?
>
> Ryan


From: Ryan Osborn on
"Zaki Shirwani" <shirwani(a)mathworks.com> wrote in message <htjmoi$gal$1(a)fred.mathworks.com>...
> Sorry, I thought you just wanted to read the value from workspace varfiable.
> If you want to both read and write, try this:
>
> %%%
> function y = fcn()
> eml.extrinsic('evalin');
> y = 0; % You need this to set the type of 'y'
> evalin('base','x = x*2');
> y = evalin('base','x')
> %%%
>
> Further reference:
> http://www.mathworks.com/access/helpdesk/help/toolbox/eml/ug/bq1h2z8-34.html#bq1h2z9-46
>
> HTH.

Thanks. But I need to be able to check the value using an if statement, then depending on the outcome of that I may need to change the value in that variable. Can this allow me to do that aswell?

Thanks,

Ryan
From: Zaki Shirwani on
Were you not able to get it to work with an IF statement in your code? The
following works for me:

function y = fcn()
%#eml
eml.extrinsic('evalin');
y = 0;
y = evalin('base','x');
if y < 100
evalin('base','x = x*2');
y = evalin('base','x');
end


"Ryan Osborn" <ryan.osborn88(a)gmail.com> wrote in message
news:htjpqd$aqn$1(a)fred.mathworks.com...
> "Zaki Shirwani" <shirwani(a)mathworks.com> wrote in message
> <htjmoi$gal$1(a)fred.mathworks.com>...
>> Sorry, I thought you just wanted to read the value from workspace
>> varfiable. If you want to both read and write, try this:
>>
>> %%%
>> function y = fcn()
>> eml.extrinsic('evalin');
>> y = 0; % You need this to set the type of 'y'
>> evalin('base','x = x*2');
>> y = evalin('base','x')
>> %%%
>>
>> Further reference:
>> http://www.mathworks.com/access/helpdesk/help/toolbox/eml/ug/bq1h2z8-34.html#bq1h2z9-46
>>
>> HTH.
>
> Thanks. But I need to be able to check the value using an if statement,
> then depending on the outcome of that I may need to change the value in
> that variable. Can this allow me to do that aswell?
>
> Thanks,
>
> Ryan


From: Ryan Osborn on
"Zaki Shirwani" <shirwani(a)mathworks.com> wrote in message <htjr4r$9ve$1(a)fred.mathworks.com>...
> Were you not able to get it to work with an IF statement in your code? The
> following works for me:
>
> function y = fcn()
> %#eml
> eml.extrinsic('evalin');
> y = 0;
> y = evalin('base','x');
> if y < 100
> evalin('base','x = x*2');
> y = evalin('base','x');
> end

OK, I still can't get this to work. Here is my actual code:

function [dem_lat, dem_long] = fcn(lat,long)

eml.extrinsic('evalin');
x = [];
x = evalin('base','wp');

if sqrt((x(1,1)-lat)^2+(x(1,2)-long)^2) <= 0.5
evalin('base','t = wp(1,:); wp(1:end-1,:) = wp(2:end,:); wp(end,:) = t');
x = evalin('base','wp');
end

dem_lat = x(1,1);
dem_long = x(1,2);

Basically I have a variable in the workspace called wp which is an array of coordinates:

wp = [5,5;5,10;10,10;10,5];

Now I have the actual lat and long of my aircraft as inputs to the function and I work out the distance between the current position and the position of the waypoint at the top is the list in the wp array. If this distance is less than 0.5 I swap the top position to the bottom of the array.

However, when it tried to compile this code, I get the following error:

Subscripting into an empty matrix is not supported.
Function 'Embedded MATLAB Function' (#58.138.144), line 7, column 14: "x(1,1)"

This sounds to me that it is not correctly fetching the contents of my wp variable, but I do not know why.

Thanks,

Ryan
From: Zaki Shirwani on
Change
x = [];
to
x = zeros(4,2); % we're basically initializing the size/type/complexity
of "x" to match "wp"

I'm assuming the size/type/complexity of "wp" won't change during the
simulation.

"Ryan Osborn" <ryan.osborn88(a)gmail.com> wrote in message
news:htkaj4$cv$1(a)fred.mathworks.com...
> "Zaki Shirwani" <shirwani(a)mathworks.com> wrote in message
> <htjr4r$9ve$1(a)fred.mathworks.com>...
>> Were you not able to get it to work with an IF statement in your code?
>> The following works for me:
>>
>> function y = fcn()
>> %#eml
>> eml.extrinsic('evalin');
>> y = 0;
>> y = evalin('base','x');
>> if y < 100
>> evalin('base','x = x*2');
>> y = evalin('base','x');
>> end
>
> OK, I still can't get this to work. Here is my actual code:
>
> function [dem_lat, dem_long] = fcn(lat,long)
>
> eml.extrinsic('evalin');
> x = [];
> x = evalin('base','wp');
> if sqrt((x(1,1)-lat)^2+(x(1,2)-long)^2) <= 0.5
> evalin('base','t = wp(1,:); wp(1:end-1,:) = wp(2:end,:); wp(end,:)
> = t');
> x = evalin('base','wp');
> end
>
> dem_lat = x(1,1);
> dem_long = x(1,2);
>
> Basically I have a variable in the workspace called wp which is an array
> of coordinates:
>
> wp = [5,5;5,10;10,10;10,5];
>
> Now I have the actual lat and long of my aircraft as inputs to the
> function and I work out the distance between the current position and the
> position of the waypoint at the top is the list in the wp array. If this
> distance is less than 0.5 I swap the top position to the bottom of the
> array.
>
> However, when it tried to compile this code, I get the following error:
>
> Subscripting into an empty matrix is not supported.
> Function 'Embedded MATLAB Function' (#58.138.144), line 7, column 14:
> "x(1,1)"
>
> This sounds to me that it is not correctly fetching the contents of my wp
> variable, but I do not know why.
>
> Thanks,
>
> Ryan