How to catenate string with variable and use this string as visa comand?

i add the value of c in string and than sendas visa command but it is not working i use two types of code below
c=1;
for i=0:10
c= 0.2+c;
u=fprintf('SOUR:VOLT %dV, (@2)',c);
fprintf(obj, 'u ');
end
also the in second try i use concatenation of string like given below
for i=1:4
%c= i+c;
s2 = 'SOUR:VOLT' ;
s1 = num2str(c);
s3 = 'V, (@2)';
s = strcat(s2,{' '},s1,s3);
fprintf(obj, 's' );
end
but instrument is not receiving proper command as is not giving output accordingly

4 件のコメント

KSSV
KSSV 2017 年 5 月 17 日
Question not clear...what is obj there? What exactly you want to do?
Santhana Raj
Santhana Raj 2017 年 5 月 17 日
I hope you are using the fopen function after creating the visa object. Another thing to check is that the instrument communicates properly for the query for id('*IDN?'). This doesn't require any string concatenation. Hence if this also works, then it might be either your string problem or wrong command problem.
Coming to your question, better to do string concatenation in a simple way as
s=['SOUR:VOLT' num2str(i+c) 'V'];
fprintf(obj,s);
Hope it helps
Muhammad Saad Naeem
Muhammad Saad Naeem 2017 年 5 月 21 日
@Santhana Raj Thanks for help, it is done by your method
Muhammad Saad Naeem
Muhammad Saad Naeem 2017 年 5 月 21 日
@KSSV obj is visa object, i wanted to send command to U2722A via visa, but i was unable to send proper command by including C value

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

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 5 月 21 日
You have
u=fprintf('SOUR:VOLT %dV, (@2)',c);
you are trying to use an integer format, %d, for a non-integer value, which is changing by 0.1 at a time. You should use
u=fprintf('SOUR:VOLT %.1fV, (@2)',c);

カテゴリ

ヘルプ センター および File ExchangeInstrument Control Toolbox についてさらに検索

質問済み:

2017 年 5 月 16 日

回答済み:

2017 年 5 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by