Unable to unclude special characters in the value of a parameter

조회 수: 2 (최근 30일)
Nikhil Jones
Nikhil Jones 2015년 1월 19일
편집: per isakson 2015년 1월 19일
Hi Guys,
I am adding a block to a pre loaded simulink system. After adding the block i need to set a specific parameter to this block of the name P and value being a dynamic value. I am using:
p = add_block('uupilib/Get data from PI-point', [par, '/', nam], 'Position', pos);
set_param(p, 'P', ['Pin(', num2str(i), ')']);
However, when i'm trying to change this to:
p = add_block('uupilib/Get data from PI-point', [par, '/', nam], 'Position', pos);
set_param(p, 'P', Pin(i).PITag);
It says "Unexpected MATLAB expression". From what i've discovered it seems that the value Pin(i).PITag contains special characters such as semi colon(;) and spaces( ). When I replace this entire string with a simple 'abc', it works again. Is there a way that i can ask MATLAB to escape these special characters?
This statement is in a loop and i here is the loop counter variable.

답변 (1개)

A Jenkins
A Jenkins 2015년 1월 19일
편집: A Jenkins 2015년 1월 19일
It used to be called genvarname().
It looks like in newer versions you are supposed to use matlab.lang.makevalidname().
I suppose you could also use regular expressions to escape only the characters you don't want.
  댓글 수: 2
Nikhil Jones
Nikhil Jones 2015년 1월 19일
Well, i went through makevalidname and i guess i specifically need the function which replaces special characters with their hexadecimal representations. But I need to decode this string when i'll be reading the block parameter from the other functions. How do i do that?
A Jenkins
A Jenkins 2015년 1월 19일
For the built in examples of how to do the replacement yourself, type doc regexprep.
There are also some people here who enjoy these puzzles for some strange reason. I bet if you put an example up (before and after of what you would like the string to be), someone would write the regular expression for you.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Naming Conventions에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by