how to divide three element array string and assign independent variable matlab?

1 次查看(过去 30 天)
hello recently I have a network analyzer equipment and I have connected it to be able to make an application in matlab, currently I have a problem when I request the values of the frequency marker that I assign in the equipment it returns a three-element string vector, I want to separate each element and assign it an independent variable to be able to manipulate that data.
fprintf(obj1,'MARKOFF');
fprintf(obj1,'MARKUNCO');
pause(5);
fprintf(obj1,'MARKDISC');
%%fprintf(obj1, "MARK1;1.5 GHZ" );
fprintf(obj1, "MARK1;" );
fprintf(obj1, "SEAMAX;" );
fprintf(obj1, "OUTPMARK;" );
%data2=scanstr(obj1,'%f');
%disp(data2);
%mkr =fscanf(obj1,'%s');
%disp(mkr);
data2=scanstr(obj1);
disp(data2);
the output display is :
[ -0.4198]
[3.9630e+18]
[ 323687500]
  4 个评论
John D'Errico
John D'Errico 2020-3-20
Yes, but that is c, not MATLAB. Do you really expect that what makes sense in one language will apply in another? By your logic, merely by my understanding English, I should also be able to speak and write flawless Chinese, French, Latin and Farsi, not to mention any of hundreds of other languages.

请先登录,再进行评论。

采纳的回答

Alberto Chavez
Alberto Chavez 2020-3-20
编辑:Alberto Chavez 2020-3-20
So it returns a string type matrix?, maybe if you try to convert it to type double you could be able to manipulate it more freely. But anyway, if you want to separate each string and assign it to different variables, you could use something like:
variable_type_1=[];
variable_type_1=[variable_type_1;output_display(1)]
% OR a vertcat command (which does the same thing)
variable_type_1=[];
variable_type_1=vertcat(variable_type_1,output_display(1))
and run this every time you have an output, your data will accumulate in each variable.
for the other variables is the same thing, you just change the name of variable and the element of the output like this:
variable_type_2=[];
variable_type_2=[variable_type_2;output_display(2)]
and so on.
edit: I should mention that if you are dealing with strings, maybe convert the variables to strings first like this:
variable_type_1=strings([]);
Does that help?

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by