![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1700911/image.png)
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
imagesc graph axis setting probelm in Matlab Appdesigner
1 回表示 (過去 30 日間)
古いコメントを表示
준홍
2024 年 5 月 21 日
...
%% Loop start
numRows = length(shiftedDistance);
numCols = app.MaxMeasCountEditField.Value;
if isempty(app.dataMatrix)
app.dataMatrix = nan(numRows, numCols);
end
app.stop_loop = false;
if isempty(app.Ascan_cnt)
app.Ascan_cnt = 0;
end
while app.Ascan_cnt <= app.MaxMeasCountEditField.Value && app.stop_loop == false
% Add new data on the dataMatrix
if app.Ascan_cnt > numCols
% If I need to add cols
app.dataMatrix = [app.dataMatrix, nan(numRows, 1)];
numCols = numCols + 1;
end
app.dataMatrix(:, app.Ascan_cnt + 1) = newData;
% NaN to Zero
app.dataMatrix(isnan(app.dataMatrix)) = 0;
% image update
imagesc(app.UIAxes3_1, [1 app.Ascan_cnt], [min(shiftedDistance) max(shiftedDistance)], app.dataMatrix);
% xlim set
if app.Ascan_cnt > 50
xlim(app.UIAxes3_1, [app.Ascan_cnt - 49 app.Ascan_cnt]);
else
xlim(app.UIAxes3_1, [1 50]);
end
% ylim set
ylim(app.UIAxes3_1, [min(shiftedDistance) max(shiftedDistance)]);
colormap(app.UIAxes3_1, 'gray');
axis(app.UIAxes3_1, 'tight');
set(app.UIAxes3_1, 'YDir', 'reverse');
clim(app.UIAxes3_1, [0, app.ImageScalingEditField.Value]);
...
My code is like those.
I have a problem on setting the X axis in the Matlab appdesigner imagesc.
I want to add measured datas one by one on the defined Matrix.
And, I want the initial X axis with 50 components, and moving through when components are over 50s.
But, the datas add along arbitrary value even not integer.
what is my problem?
11 件のコメント
Angelo Yeo
2024 年 5 月 21 日
I need more information. I need your app and reproduction steps. I created a random app based on your description but I don't know what the issue is. Please take a look at my attachment and tell me how to reproduce your issue.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1700911/image.png)
준홍
2024 年 5 月 22 日
編集済み: Voss
2024 年 5 月 22 日
Here is total code, sorry for messy comments.
function AscansLoopStart(app)
%% 거리축 정의 및 circshift
% 음의 거리 영역 순환 이동
negativeDistance = find(app.Distance < 0);
% 순환 이동할 인덱스 계산
shift_index = length(negativeDistance);
% Shifted Axis 재정의
shiftedDistance = circshift(app.Distance, -shift_index);
shiftedDistanceValue = (length(shiftedDistance) - shift_index : length(shiftedDistance) - 1) * app.DistanceStep;
shiftedDistance(end - shift_index + 1 : end) = shiftedDistanceValue;
%% 셋팅값 저장
% 현재 작업 디렉토리에서 데이터 저장을 위한 폴더 생성
currentDir = pwd; % 현재 작업 디렉토리 경로
baseFolder = fullfile(currentDir, datestr(now, 'yyyy-mm-dd_HH-MM-SS'));
mkdir(baseFolder); % 현재 시간 기준 폴더 생성
for k = 1:4
mkdir(baseFolder, ['Port' num2str(k)]);
end
% 측정 관련 셋팅값 데이터 저장
SettingValues = struct();
SettingValues.FrequencyAxis = app.FrequencyAxis;
SettingValues.StartFrequency = app.StartFrequency;
SettingValues.StopFrequency = app.StopFrequency;
SettingValues.FreqStep = app.FrequencyStep;
SettingValues.IFBandwidth = app.IFBW;
SettingValues.FreqdomainInputPulse = app.FreqdomainInputPulse;
SettingValues.InputPulseBandwidth = app.InputPulseBandwidth;
SettingValues.InputPulsePeakFrequency = app.PeakFrequency;
SettingValues.InputPulseCarrierFrequency = app.CarrierFrequency;
SettingValues.TimeAxis = app.TimeAxis;
SettingValues.TimeStep = app.TimeStep;
SettingValues.TimedomainInputPulse = app.TimedomainInputPulse;
SettingValues.shiftedDistance = shiftedDistance;
SettingValues.shift_index = shift_index;
% 설정값 .mat 파일로 저장
settings_filename = fullfile(baseFolder, 'SettingValues.mat');
save(settings_filename, '-struct', 'SettingValues');
%% Loop start
numRows = length(shiftedDistance); % y축 데이터 길이
numCols = app.MaxMeasCountEditField.Value; % 최대 측정 횟수
% 기존 데이터가 없으면 초기화
if isempty(app.dataMatrix)
app.dataMatrix = nan(numRows, numCols); % 데이터를 저장할 행렬, 초기값은 NaN
end
app.stop_loop = false;
app.StatusTextArea.Value = 'loop started';
% Count가 비어있으면 초기화
if isempty(app.Ascan_cnt)
app.Ascan_cnt = 0;
end
while app.Ascan_cnt <= app.MaxMeasCountEditField.Value && app.stop_loop == false
measurements = {'S11', 'S22', 'S12', 'S21'};
data = cell(length(measurements), 1);
% 스위치별 for loop 시작
for count = 1:4
switch count
case 1
outputSingleScan(app.SwitchSession, app.RF1_ON);
app.RFSwitchStatus = 1;
case 2
outputSingleScan(app.SwitchSession, app.RF2_ON);
app.RFSwitchStatus = 2;
case 3
outputSingleScan(app.SwitchSession, app.RF3_ON);
app.RFSwitchStatus = 3;
case 4
outputSingleScan(app.SwitchSession, app.RF4_ON);
app.RFSwitchStatus = 4;
end
% 정의된 스위치를 기준으로 각 Sparam 측정 시작
for i = 1:length(measurements)
measurement = measurements{i};
% 윈도우 활성화
fprintf(app.visaobj, 'DISP:WIND1:STAT ON');
% 측정 설정 (CALC(채널))
fprintf(app.visaobj, sprintf('CALC:MEAS%d:DEF ''%s''', i, measurement));
% 측정 format 설정
fprintf(app.visaobj, sprintf('CALC:MEAS%d:FORM COMP ', i));
% 측정 데이터 윈도우에 표시
fprintf(app.visaobj, ['DISP:MEAS' num2str(i) ':FEED 1']);
% 채널 설정 (1: 채널 1)
fprintf(app.visaobj, sprintf('CALC:PAR:MNUM 1'));
% 스윕 타입 설정 (LIN: 선형, LOG: 로그)
fprintf(app.visaobj, 'SENS:SWE:TYPE LIN');
% 스윕 시작
fprintf(app.visaobj, 'SENS:SWE:MODE CONT');
% 스윕 완료 기다림
app.visaobj.query('*OPC?');
% 측정 데이터 가져오기
command = sprintf('CALC:MEAS%d:DATA:FDATa?', i);
data{i} = str2num(app.visaobj.query(command));
end
% 측정 데이터 사전할당
data_real = cell(size(data))';
data_imag = cell(size(data))';
% 측정 데이터 실수, 허수 영역 분리
for i = 1:length(data)
data_real{i} = data{i}(1:2:end);
data_imag{i} = data{i}(2:2:end);
end
% 측정 데이터 complex 값으로 변환
S11 = transpose(data_real{1} + data_imag{1}*1i);
S22 = transpose(data_real{2} + data_imag{2}*1i);
S12 = transpose(data_real{3} + data_imag{3}*1i);
S21 = transpose(data_real{4} + data_imag{4}*1i);
% 데이터 저장 및 Plot
switch app.RFSwitchStatus
case 1
% 저장할 데이터 구조체 생성
Measdata = struct();
Measdata.Frequency = app.FrequencyAxis;
Measdata.S11 = S11;
Measdata.S22 = S22;
Measdata.S12 = S12;
Measdata.S21 = S21;
Measdata_table = struct2table(Measdata);
% 데이터 .csv 형식으로 저장
filename = fullfile(baseFolder, 'Port1', sprintf('data_%06d.csv', app.Ascan_cnt));
writetable(Measdata_table, filename);
% 시각화 할 데이터 Calibration 적용
CalibratedData_S21 = (S21 - app.Background_signal_SwitchPort1{4}) ./ app.ThruCalData_SwitchPort1;
% 시각화 할 데이터 Full domain으로 변경
FullCalibratedData_S21 = [0; CalibratedData_S21; zeros(app.ZeroPadding, 1); zeros(app.ZeroPadding, 1); conj(CalibratedData_S21(end:-1:1))];
% 시영역 신호 확인
VreflFreq_S21 = FullCalibratedData_S21 .* app.FreqdomainInputPulse;
VreflTime_S21 = ifft(VreflFreq_S21);
% 새로운 데이터를 생성 또는 가져오기
shiftedDistancedata_SwitchPort1 = circshift(VreflTime_S21, -shift_index);
newData = abs(shiftedDistancedata_SwitchPort1); % 새로운 y축 데이터
newData = newData(:); % 열 벡터로 변환
% 데이터 매트릭스에 새로운 데이터 추가
if app.Ascan_cnt > numCols
% 열을 추가해야 할 경우
app.dataMatrix = [app.dataMatrix, nan(numRows, 1)];
numCols = numCols + 1;
end
app.dataMatrix(:, app.Ascan_cnt + 1) = newData;
% NaN을 0으로 변환 (imagesc를 위해)
app.dataMatrix(isnan(app.dataMatrix)) = 0;
%%
% 데이터 매트릭스에 새로운 데이터 추가
% app.dataMatrix(:, app.Ascan_cnt + 1) = newData;
% app.dataMatrix(isnan(app.dataMatrix)) = 0;
%%
% 이미지 업데이트
imagesc(app.UIAxes3_1, [1 app.Ascan_cnt], [min(shiftedDistance) max(shiftedDistance)], app.dataMatrix);
% x축 제한 설정
if app.Ascan_cnt > 50
xlim(app.UIAxes3_1, [app.Ascan_cnt - 49 app.Ascan_cnt]);
else
xlim(app.UIAxes3_1, [1 50]);
end
% y축 범위 설정 (shiftedDistance의 실제 거리값 사용)
ylim(app.UIAxes3_1, [min(shiftedDistance) max(shiftedDistance)]);
% 그레이스케일 적용
colormap(app.UIAxes3_1, 'gray');
% 그래프 조정
axis(app.UIAxes3_1, 'tight');
set(app.UIAxes3_1, 'YDir', 'reverse');
clim(app.UIAxes3_1, [0, app.ImageScalingEditField.Value]);
case 2
% 저장할 데이터 구조체 생성
Measdata = struct();
Measdata.Frequency = app.FrequencyAxis;
Measdata.S11 = S11;
Measdata.S22 = S22;
Measdata.S12 = S12;
Measdata.S21 = S21;
Measdata_table = struct2table(Measdata);
% 데이터 .csv 형식으로 저장
filename = fullfile(baseFolder, 'Port2', sprintf('data_%06d.csv', app.Ascan_cnt));
writetable(Measdata_table, filename);
% 시각화 할 데이터 Calibration 적용
CalibratedData_S21 = (S21 - app.Background_signal_SwitchPort2{4}) ./ app.ThruCalData_SwitchPort2;
% 시각화 할 데이터 Full domain으로 변경
FullCalibratedData_S21 = [0; CalibratedData_S21; zeros(app.ZeroPadding, 1); zeros(app.ZeroPadding, 1); conj(CalibratedData_S21(end:-1:1))];
% 시영역 신호 확인
VreflFreq_S21 = FullCalibratedData_S21 .* app.FreqdomainInputPulse;
VreflTime_S21 = ifft(VreflFreq_S21);
% 새로운 데이터를 생성 또는 가져오기
shiftedDistancedata_SwitchPort2 = circshift(VreflTime_S21, -shift_index);
newData = abs(shiftedDistancedata_SwitchPort2); % 새로운 y축 데이터
newData = newData(:); % 열 벡터로 변환
% 데이터 매트릭스에 새로운 데이터 추가
if app.Ascan_cnt > numCols
% 열을 추가해야 할 경우
app.dataMatrix = [app.dataMatrix, nan(numRows, 1)];
numCols = numCols + 1;
end
app.dataMatrix(:, app.Ascan_cnt + 1) = newData;
% NaN을 0으로 변환 (imagesc를 위해)
app.dataMatrix(isnan(app.dataMatrix)) = 0;
% 이미지 업데이트
imagesc(app.UIAxes3_2, [1 app.Ascan_cnt], [min(shiftedDistance) max(shiftedDistance)], app.dataMatrix);
% x축 제한 설정
if app.Ascan_cnt > 50
xlim(app.UIAxes3_2, [app.Ascan_cnt - 49 app.Ascan_cnt]);
else
xlim(app.UIAxes3_2, [1 50]);
end
% y축 범위 설정 (shiftedDistance의 실제 거리값 사용)
ylim(app.UIAxes3_2, [min(shiftedDistance) max(shiftedDistance)]);
% 그레이스케일 적용
colormap(app.UIAxes3_2, 'gray');
% 그래프 조정
axis(app.UIAxes3_2, 'tight');
set(app.UIAxes3_2, 'YDir', 'reverse');
clim(app.UIAxes3_2, [0, app.ImageScalingEditField.Value]);
case 3
% 저장할 데이터 구조체 생성
Measdata = struct();
Measdata.Frequency = app.FrequencyAxis;
Measdata.S11 = S11;
Measdata.S22 = S22;
Measdata.S12 = S12;
Measdata.S21 = S21;
Measdata_table = struct2table(Measdata);
% 데이터 .csv 형식으로 저장
filename = fullfile(baseFolder, 'Port3', sprintf('data_%06d.csv', app.Ascan_cnt));
writetable(Measdata_table, filename);
% 시각화 할 데이터 Calibration 적용
CalibratedData_S21 = (S21 - app.Background_signal_SwitchPort3{4}) ./ app.ThruCalData_SwitchPort3;
% 시각화 할 데이터 Full domain으로 변경
FullCalibratedData_S21 = [0; CalibratedData_S21; zeros(app.ZeroPadding, 1); zeros(app.ZeroPadding, 1); conj(CalibratedData_S21(end:-1:1))];
% 시영역 신호 확인
VreflFreq_S21 = FullCalibratedData_S21 .* app.FreqdomainInputPulse;
VreflTime_S21 = ifft(VreflFreq_S21);
% 새로운 데이터를 생성 또는 가져오기
shiftedDistancedata_SwitchPort3 = circshift(VreflTime_S21, -shift_index);
newData = abs(shiftedDistancedata_SwitchPort3); % 새로운 y축 데이터
newData = newData(:); % 열 벡터로 변환
% 데이터 매트릭스에 새로운 데이터 추가
if app.Ascan_cnt > numCols
% 열을 추가해야 할 경우
app.dataMatrix = [app.dataMatrix, nan(numRows, 1)];
numCols = numCols + 1;
end
app.dataMatrix(:, app.Ascan_cnt + 1) = newData;
% NaN을 0으로 변환 (imagesc를 위해)
app.dataMatrix(isnan(app.dataMatrix)) = 0;
% 이미지 업데이트
imagesc(app.UIAxes3_3, [1 app.Ascan_cnt], [min(shiftedDistance) max(shiftedDistance)], app.dataMatrix);
% x축 제한 설정
if app.Ascan_cnt > 50
xlim(app.UIAxes3_3, [app.Ascan_cnt - 49 app.Ascan_cnt]);
else
xlim(app.UIAxes3_3, [1 50]);
end
% y축 범위 설정 (shiftedDistance의 실제 거리값 사용)
ylim(app.UIAxes3_3, [min(shiftedDistance) max(shiftedDistance)]);
% 그레이스케일 적용
colormap(app.UIAxes3_3, 'gray');
% 그래프 조정
axis(app.UIAxes3_3, 'tight');
set(app.UIAxes3_3, 'YDir', 'reverse');
clim(app.UIAxes3_3, [0, app.ImageScalingEditField.Value]);
case 4
% 저장할 데이터 구조체 생성
Measdata = struct();
Measdata.Frequency = app.FrequencyAxis;
Measdata.S11 = S11;
Measdata.S22 = S22;
Measdata.S12 = S12;
Measdata.S21 = S21;
Measdata_table = struct2table(Measdata);
% 데이터 .csv 형식으로 저장
filename = fullfile(baseFolder, 'Port4', sprintf('data_%06d.csv', app.Ascan_cnt));
writetable(Measdata_table, filename);
% 시각화 할 데이터 Calibration 적용
CalibratedData_S21 = (S21 - app.Background_signal_SwitchPort4{4}) ./ app.ThruCalData_SwitchPort4;
% 시각화 할 데이터 Full domain으로 변경
FullCalibratedData_S21 = [0; CalibratedData_S21; zeros(app.ZeroPadding, 1); zeros(app.ZeroPadding, 1); conj(CalibratedData_S21(end:-1:1))];
% 시영역 신호 확인
VreflFreq_S21 = FullCalibratedData_S21 .* app.FreqdomainInputPulse;
VreflTime_S21 = ifft(VreflFreq_S21);
% 새로운 데이터를 생성 또는 가져오기
shiftedDistancedata_SwitchPort4 = circshift(VreflTime_S21, -shift_index);
newData = abs(shiftedDistancedata_SwitchPort4); % 새로운 y축 데이터
newData = newData(:); % 열 벡터로 변환
% 데이터 매트릭스에 새로운 데이터 추가
if app.Ascan_cnt > numCols
% 열을 추가해야 할 경우
app.dataMatrix = [app.dataMatrix, nan(numRows, 1)];
numCols = numCols + 1;
end
app.dataMatrix(:, app.Ascan_cnt + 1) = newData;
% NaN을 0으로 변환 (imagesc를 위해)
app.dataMatrix(isnan(app.dataMatrix)) = 0;
% 이미지 업데이트 (그래프를 그릴 대상, x축의 범위 및, 1부터 시작하여 현재측정 대상까지, y축 범위, 시각화할 데이터 )
imagesc(app.UIAxes3_4, [1 app.Ascan_cnt], [min(shiftedDistance) max(shiftedDistance)], app.dataMatrix);
% x축 제한 설정
if app.Ascan_cnt > 50
xlim(app.UIAxes3_4, [app.Ascan_cnt - 49 app.Ascan_cnt]);
else
xlim(app.UIAxes3_4, [1 50]);
end
% y축 범위 설정 (shiftedDistance의 실제 거리값 사용)
ylim(app.UIAxes3_4, [min(shiftedDistance) max(shiftedDistance)]);
% 그레이스케일 적용
colormap(app.UIAxes3_4, 'gray');
% 그래프 조정
axis(app.UIAxes3_4, 'tight');
set(app.UIAxes3_4, 'YDir', 'reverse');
clim(app.UIAxes3_4, [0, app.ImageScalingEditField.Value]);
end
app.StatusTextArea.Value = 'Switching 진행 중';
pause(0.1);
end % 스위치 for loop end
% Scan 횟수 표기
app.StatusTextArea.Value = sprintf('%d번째 scan 측정 완료', app.Ascan_cnt);
% offset 업데이트
app.offset = app.offset + 1;
% Count 업데이트
app.Ascan_cnt = app.Ascan_cnt + 1;
pause(0.1);
end % While loop end
end
준홍
2024 年 5 月 22 日
移動済み: Angelo Yeo
2024 年 5 月 22 日
And this is example result image.
As you can see, count is not integer. And the X axis is set by the A scan count number, not determined by code.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1701366/image.png)
VBBV
2024 年 5 月 22 日
if app.Ascan_cnt > numCols
% 열을 추가해야 할 경우
app.dataMatrix = [app.dataMatrix, nan(numRows, 1)]; % numRows or numCols ?
numCols = numCols + 1;
end
VBBV
2024 年 5 月 23 日
編集済み: VBBV
2024 年 5 月 23 日
Ok. It may be for this reason, using sprintf function when you print to status text area value. This function prints output values in text or as character instead of numeric (double) values. Use without sprintf function as shown below
app.StatusTextArea.Value = app.Ascan_cnt
回答 (1 件)
VBBV
2024 年 5 月 23 日
編集済み: VBBV
2024 年 5 月 24 日
@준홍Ok. It may be for this reason, using *sprintf* function when you print to status text area value. This function prints output values in text or as character instead of numeric (double) values. Use without |sprintf| function as shown below
app.StatusTextArea.Value = app.Ascan_cnt
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)