I'm trying to run an instrument (that understands scpi commmands) four times. It stores its data in different rows and columns within the same array. As there are four variables, running four times, there are sixteen columns. There are also twenty-one data points, so there are twenty-one data rows. I'm trying to append the array, and it's not working for some reason. All the code within the "for" function works like a charm, except for the last four lines. Is there a bug that I'm not seeing? Thank you.
global analyzerData;
analyzerData = zeros(21,16);
global i
for i = 1:4
disp(i)
strcat('PAGE:CHAN:SMU', int2str(mod(i,4)), ':MODE COMM'); % Set the first SMU to COMM
strcat('PAGE:CHAN:SMU', int2str(mod(i,4)), ":INAME 'IS'"); % Set current name
strcat('PAGE:CHAN:SMU', int2str(mod(i,4)), ":VNAME 'VS'"); % Set voltage name
strcat('PAGE:CHAN:SMU', int2str(mod(i+1,4)), ':MODE V'); % Set the next SMU to current mode
strcat('PAGE:CHAN:SMU', int2str(mod(i+1,4)), ':FUNC VAR1'); % see if VAR1 works. If not, then change to different variables
strcat('PAGE:CHAN:SMU', int2str(mod(i+1,4)), ":INAME 'ID'"); % Set current name
strcat('PAGE:CHAN:SMU', int2str(mod(i+1,4)), ":VNAME 'VD'"); % Set voltage name
strcat('PAGE:CHAN:SMU', int2str(mod(i+2,4)), ':DIS'); % Disable third SMU
strcat('PAGE:CHAN:SMU', int2str(mod(i+3,4)), ':DIS'); % Disable fourth SMU
fprintf(analyzer, 'PAGE:MEAS:VAR1:MODE SING'); % Do execution only once
fprintf(analyzer, 'PAGE:MEAS:VAR1:START 0'); % Start
fprintf(analyzer, 'PAGE:MEAS:VAR1:STEP 0.05'); % Steps
fprintf(analyzer, 'PAGE:MEAS:VAR1:STOP 1.0'); % Stop
fprintf(analyzer, 'PAGE:MEAS:VAR1:COMP 0.1'); % Compliance
fprintf(analyzer, 'PAGE:MEAS:DEL 0.01'); % Timing. Also experiment with this value for speed and accuracy
fprintf(analyzer, 'PAGE:SCON:SING'); % Single execution
fprintf(analyzer, '*WAI'); % Wait until the command is done
analyzerData(:,((i-1)*4)+0) = transpose(str2num(query(analyzer, "DATA? 'VS'")));
analyzerData(:,((i-1)*4)+1) = transpose(str2num(query(analyzer, "DATA? 'IS'")));
analyzerData(:,((i-1)*4)+2) = transpose(str2num(query(analyzer, "DATA? 'VD'")));
analyzerData(:,((i-1)*4)+3) = transpose(str2num(query(analyzer, "DATA? 'ID'")));
end

 채택된 답변

dpb
dpb 2018년 7월 17일
analyzerData(:,((i-1)*4)+4) = transpose(str2num(query(analyzer, "DATA? 'VS'")));
analyzerData(:,((i-1)*4)+4) = transpose(str2num(query(analyzer, "DATA? 'IS'")));
analyzerData(:,((i-1)*4)+4) = transpose(str2num(query(analyzer, "DATA? 'VD'")));
analyzerData(:,((i-1)*4)+4) = transpose(str2num(query(analyzer, "DATA? 'ID'")));
Each of the four is writing to the same column instead of sequential
analyzerData(:,((i-1)*4)+4+0) = transpose(str2num(query(analyzer, "DATA? 'VS'")));
analyzerData(:,((i-1)*4)+4+1) = transpose(str2num(query(analyzer, "DATA? 'IS'")));
analyzerData(:,((i-1)*4)+4+2) = transpose(str2num(query(analyzer, "DATA? 'VD'")));
analyzerData(:,((i-1)*4)+4+3) = transpose(str2num(query(analyzer, "DATA? 'ID'")));
to make it explicitly clear; I'd probably recast to compute the indices only once thru the loop, but the overhead isn't enough to matter significantly.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2018년 7월 17일

편집:

2018년 7월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by