Plotting a bode graph extracted from LTSPICE simulator

10 visualizzazioni (ultimi 30 giorni)
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');

Risposta accettata

Star Strider
Star Strider il 27 Ago 2020
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 Commenti
Juan Carlos Maturana Renteria
Thanks for the help, I've been struggling for 4 hours with this code.
I just have a final question and it's that I tryed your code with another .text file but it didn't work, so it's a parameter that I am missing that has to chage for each bode graph?
again, thank for the help man.
Star Strider
Star Strider il 27 Ago 2020
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.)

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by