How to parse a string in simulink?
7 views (last 30 days)
Show older comments
We have a variable in our base workspace that is a string that we would like to read into simulink. We then would like to parse the string to pull out the important values. Our problems include: 1) Getting Simulink to pull the string from the workspace. 2) Parsing the string to find the important values. 3) Converting the important string values to numbers.
We are looking for any input/suggestions. Thanks for your time!
PS Here is code we would like to implement in Simulink but only works in Matlab right now.
function [tag1] = tagParseTest
% Function takes in data stream from 'base' workspace
%%Take in data
% Extracting dataOut variable in workspace
% dataOut is in this format: (<TagID>, <X>, <Y>)
tagData = evalin('base', 'dataOut');
%Parse Tag data into x, y
% Finding the correct delimiters for tag1
comma = strfind(tagData, ',');
x = str2double(tagData((comma(1)+2):(comma(2))));
y = str2double(tagData((comma(2)+2):(end-1)));
%Format function output for input into Heading Conditioner blocks
tag1 = [x, y];
Ryan G on 22 Mar 2013
If you want to use strings in Simulink, particularly if you want to generate code, I would suggest converting to ASCII characters and performing operations in that domain.
returns 44, so instead of using strfind you can simply look for 44 in the data and split it up that way.
Using ascii directly will help you avoid using characters in simulink, which is not easy to do. This will open up the ability to pass character data using simulink blocks where you can later recode into a string if needed.
Find more on String 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!