How to write a variable in a Vector with a loop

5 visualizaciones (últimos 30 días)
Zawar Salim
Zawar Salim el 27 de Feb. de 2023
Comentada: Zawar Salim el 27 de Feb. de 2023
Hi MATLAB community
Im sitting here on a problem maybe i can get here some help. I have the feeling im close but i cant get it. I searched for countless websites....
I have a Instrument that writes its Reading in a Value rv1. rv1 is is from type num. I have a vector RVM=zeros (1,3). My Goal is to write a loop which writes the curent value of rv1 in every place of the vector
this is my code...
RVM=zeros(1,3)
for i2=1:length(RVM)
fprintf(DMM_Current2,read_current);
rv1=fscanf(DMM_Current2)
rv1= str2num(rv1);
i want RVM so show this [value rv1 first loop value, rv1 second loop, rv1 third loop .......]
sry if im asking a trivial question... im new to MATLAB and i couldnt find something usefull in the MATLAB handbook

Respuesta aceptada

Rik
Rik el 27 de Feb. de 2023
If you have trouble with Matlab basics you may consider doing the Onramp tutorial (which is provided for free by Mathworks). See below for some advice and the line of code you likely needed.
for i2=1:numel(RVM) % use numel instead of length
fprintf(DMM_Current2,read_current); % why is this here?
rv1 = fscanf(DMM_Current2);
rv1 = str2double(rv1); % use str2double instead of str2num
RVM(i2) = rv1;
end
  1 comentario
Zawar Salim
Zawar Salim el 27 de Feb. de 2023
thx i will do that... im a student and i have actually passed a Moodule about Matlab basics. Im just Rusty because if was before corona XD. That code is part of a Project im doing.
for i2=1:numel(RVM) % thx
fprintf(DMM_Current2,read_current); % this Command saves the readed value in the Intsrument
rv1 = fscanf(DMM_Current2); % this give the command to apply it.. so this and the command before are mandatory to get the right value from the intrument.
rv1 = str2double(rv1); % the , yes double is more precise
RVM(i2) = rv1;
end

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by