how to divide three element array string and assign independent variable matlab?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Gerbin Gaytan Rivera
el 20 de Mzo. de 2020
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 comentarios
John D'Errico
el 20 de Mzo. de 2020
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.
Respuesta aceptada
Alberto Chavez
el 20 de Mzo. de 2020
Editada: Alberto Chavez
el 20 de Mzo. de 2020
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?
Más respuestas (0)
Ver también
Categorías
Más información sobre Tables en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!