Hello,
I'm exporting some constants from Simulink to the Matlab workspace. The variables are called A1, A2, A3, B1, B2,....
I want to access the variables in this way:
variables_names={'A1', 'A2', 'A3', 'B1'}
for i=1:length(variable_names),
bi2de(variable_names(1,i))
end;
The variables are arrays of [1,11] size with doubles values. I've tried to use the eval function but didn't get it to work.
|
|
0
|
|
|
|
Reply
|
Martin
|
3/9/2010 4:11:04 PM |
|
"Martin Stolpe" <martin.stople@uni-ulm.de> wrote in message <hn5ruo$rjj$1@fred.mathworks.com>...
> Hello,
> I'm exporting some constants from Simulink to the Matlab workspace. The variables are called A1, A2, A3, B1, B2,....
>
> I want to access the variables in this way:
>
> variables_names={'A1', 'A2', 'A3', 'B1'}
>
> for i=1:length(variable_names),
> bi2de(variable_names(1,i))
> end;
>
> The variables are arrays of [1,11] size with doubles values. I've tried to use the eval function but didn't get it to work.
With cell arrays, you should use {} instead of ().
>> out = eval(['bi2de(',variable_names{1,i},')']);
|
|
0
|
|
|
|
Reply
|
Husam
|
3/9/2010 4:53:04 PM
|
|
"Martin Stolpe" <martin.stople@uni-ulm.de> wrote in message <hn5ruo$rjj$1@fred.mathworks.com>...
> Hello,
> I'm exporting some constants from Simulink to the Matlab workspace. The variables are called A1, A2, A3, B1, B2,....
>
> I want to access the variables in this way:
>
> variables_names={'A1', 'A2', 'A3', 'B1'}
>
> for i=1:length(variable_names),
> bi2de(variable_names(1,i))
> end;
I think the following is what you want, but it's hard to tell. Your code doesn't assign the ouput of bi2de to anything
variables_names={'A1', 'A2', 'A3', 'B1'};
for i=1:length(variable_names),
thisVar=variables_names{i};
myStruct(thisVar)=bi2de(eval(thisVar));
end;
|
|
0
|
|
|
|
Reply
|
Matt
|
3/9/2010 4:58:05 PM
|
|
Thanks a lot. This solution does what I want. Here is the current code:
% Convert the values from binary coefficients to hex values;
coefficients = {'A1', 'A2', 'A3', 'B1', 'B2', 'B3', 'C1', 'C2', 'C3', 'D13', 'D14', 'D24', 'E21', 'E31', 'E32'};
hex_coeff_array = cell(length(coefficients), 2);
for i=1:length(coefficients),
thisVar=coefficients{i};
hex_coeff_array(i,1) = cellstr(thisVar);
hex_coeff_array(i, 2) = cellstr(dec2hex(bi2de(fliplr(eval(thisVar))), 8));
end;
|
|
0
|
|
|
|
Reply
|
Martin
|
3/10/2010 4:54:04 PM
|
|
|
3 Replies
327 Views
(page loaded in 0.088 seconds)
Similiar Articles: access variable by string name - comp.soft-sys.matlabHello, I'm exporting some constants from Simulink to the Matlab workspace. The variables are called A1, A2, A3, B1, B2,.... I want to access the v... Purpose of a string variable in a FSM process - comp.lang.vhdl ...access variable by string name - comp.soft-sys.matlab access variable by string ... text processing questions - comp.lang.vhdl... this help me write code like: variable ... Insert variable into string - comp.soft-sys.matlabaccess variable by string name - comp.soft-sys.matlab Insert variable into string - comp.soft-sys.matlab converting a character string into a variable name - comp.lang ... Changing variable name in for loop - comp.soft-sys.matlab ...access variable by string name - comp.soft-sys.matlab changing the variable name in a FOR loop - comp.soft-sys.matlab ..... variable[I],rate); end Do you know how to ... Passing stem variables to an external subroutine - comp.lang.rexx ...access variable by string name - comp.soft-sys.matlab Passing stem variables to an external subroutine - comp.lang.rexx ... My other solution is to convert the stem ... Get variable by name - comp.lang.asm.x86access variable by string name - comp.soft-sys.matlab Get variable by name - comp.lang.asm.x86 access to workspace variable - comp.soft-sys.matlab How to get to a content ... Setting a breakpoint on variable access - comp.lang.asm.x86 ...access variable by string name - comp.soft-sys.matlab Setting a breakpoint on variable access - comp.lang.asm.x86 ..... variable name and value - comp.soft-sys.math ... Local array variables in functions - comp.lang.awkaccess variable by string name - comp.soft-sys.matlab MASM_LOCAL variable ... Any ordinary variable name can be ... of line; type line_set is access line_array_t; variable ... MASM_LOCAL variable - comp.lang.asm.x86access variable by string name - comp.soft-sys.matlab Why not simply build a string ... VisualC++ question (accessing external global ... MASM_LOCAL variable ... changing the variable name in a FOR loop - comp.soft-sys.matlab ...... variable[I],rate); end Do you know how to implement this strategy of changing the variable name on a FOR loop? Other possibility could be access a string ... access variable by string name - Newsreader - MATLAB CentralHello, I'm exporting some constants from Simulink to the Matlab workspace. The variables are called A1, A2, A3, B1, B2,.... I want to access the variables in this way: How To Use a Variable In a SQL String VBA | eHow.comstrSQL = "SELECT Employees.[First Name], "strSQL = strSQL & "Employees ... Applications (VBA) is a programming language used for Microsoft Access. You set a string variable ... 7/24/2012 12:57:05 AM
|