How to parse a string in simulink?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 data
%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];
end
0 Kommentare
Antworten (1)
Ryan G
am 22 Mär. 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.
double(',')
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu String finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!