creating a variable address

11 views (last 30 days)
Amir amini
Amir amini on 8 Feb 2020
Commented: Stephen23 on 8 Feb 2020
I linked Matlab software with a engineering software. MATLAB software must generate a new address every time it can be used in engineering software. The general format of the addresses in the engineering software is as follows:
A.Application.Tree.FindNode('Data\Blocks\variable component\Input\MODEL_TYPE').value
that 'variable component' change every time and When this changes; The address also changes with it.
How can I creat a variable address?
is below code correct?
for i=3:size(strtbl,2)
val_type(i)=sprintf('''A.Application.Tree.FindNode(''\Data\Blocks\%s\Input\MODEL_TYPE'')''',strtbl(3,i));
end
matlab response:
Function is not defined for 'cell' inputs.
Error in Program (line 42)
val_type(i)=sprintf('''A.Application.Tree.FindNode(''\Data\Blocks\%s\Input\MODEL_TYPE'')''',strtbl(3,i));

Accepted Answer

Giuseppe Inghilterra
Giuseppe Inghilterra on 8 Feb 2020
Hi,
i recommend you to use "fullfile" matlab function. This function allows you to build addresses from parts.
Thus, in your case:
variablecomponent = 'text';
fullfile('Data','Blocks',variablecomponent,'Input','MODEL_TYPE');
Thus, you vary in your for loop variablecomponent and you obtain a variable address.
Note that if variablecomponent is a cell array, where each cell contains a character array, remember to use {} brackets in your for loop. Otherwise the output of fullfile function is not a character array, but a cell array and maybe your function 'A.Application.Tree.FindNode' does not accept a cell array as input argument.
Hope this helps.

More Answers (0)

Categories

Find more on Data Type Conversion 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!