
Plotting a bode graph extracted from LTSPICE simulator
조회 수: 10 (최근 30일)
이전 댓글 표시
hi,
i'm trying to plot a bode graph but at the moment of show in it on matlab the graph doesn't show up, but just the axes thought. What happen is that the 'D' variable is just saving the first row, but not the rest. I have been looking on the documentation of 'textscan' and it says that if the parameter 'formatSpec' doesn't match with the text field, it will throw a error and save the the prebius rows, yet my every rows in the .text is the same.
Here is my code (text field attached) if maybe it's someting wrong with it. I will really apreciate the help.
archivo = fopen('DatosBodeFinal.txt');
Dc = textscan(archivo, '%f (%fdB,%f°)','CollectOutput',1);
fclose(archivo);
D = cell2mat(Dc);
disp(Dc);
figure
subplot(2,1,1);
semilogx(D(:,1), D(:,2),'Color','k','LineWidth',3);
ylabel('Amplitude (dB)');
grid
subplot(2,1,2);
semilogx(D(:,1), D(:,3),'Color','k','LineWidth',3);
ylabel('Phase (°)');
grid
xlabel('Frequency');
댓글 수: 0
채택된 답변
Star Strider
2020년 8월 27일
This works for me:
filename = 'DatosBodeFinal.txt';
fidi = fopen(filename, 'rt');
Dc = textscan(fidi, '%f(%fdB,%f°)', 'CollectOutput',1);
D = cell2mat(Dc);
figure
subplot(2,1,1)
semilogx(D(:,1), D(:,2))
title('Amplitude (dB)')
grid
subplot(2,1,2)
semilogx(D(:,1), D(:,3))
title('Phase (°)')
grid
xlabel('Frequency')
and produces this plot:

.
댓글 수: 2
Star Strider
2020년 8월 27일
As always, my pleasure!
I have no idea what the problem may be with your other files, that I assume are also LTSPICE files. If they have the same format as this one, my code should work with them. Your Question is the second about LTSPICE files that I have replied to (you already discovered the other one), and the same code worked with both of them. That is also the same code I used here. It may be the version of MATLAB you are using, so also be ccertain you have the latest Updates. (I am using R2020a, however this code also worked with whatever version worked with the previous Question, that I believe was R2019a, although I do not remember just now.)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!