フィルターのクリア

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

2 ビュー (過去 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.
Gerbin Gaytan Rivera
Gerbin Gaytan Rivera 2020 年 3 月 20 日
thank you !

サインインしてコメントする。

採用された回答

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?
  1 件のコメント
Gerbin Gaytan Rivera
Gerbin Gaytan Rivera 2020 年 3 月 23 日
if a wish to convert variable_type_1=[]; and variable_type_2=[]; to number ,
How can I convert the result to a number?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by