Info

This question is closed. Reopen it to edit or answer.

problem to plot graph

1 view (last 30 days)
Israt Jahan
Israt Jahan on 21 Apr 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
I am try to plot graph from excel file using matlab.it is 2 column and 1000 row file. I got problem and don't know how to solve this problem.
My codes are
a = xlsread('frequencyresponse_cone2.xlsx');
U = a(:,2);
mag = 20*log10(abs(U));
f = a(:,1);
semilogx(f,mag);
grid;
title('Voltage Divider')
xlabel('Frequency [Hz]')
ylabel('Magnitude [dB]')
sys=frd(abs(U),f);
bd=bandwidth(sys)
I have got this following error
Attempted to access a(:,2); index out of bounds because size(a)=[1000,1].
Error in ploting_bandwidth_plex_shield (line 4)
U = a(:,2);
I can not understand the problem. I put some of my data from file.
100 0.012306987852045518+9.955546191163225E-9i
1001100.901 0.012308491603736954+9.963642914141967E-5i
2002101.802 0.012312995435215674+1.9909141167179524E-4i
3003102.703 0.012320478963642677+2.9820480108037103E-4i
4004103.604 0.012330908495129297+3.9680921522587394E-4i
5005104.505 0.012344237432945524+4.947412933337127E-4i
6006105.405 0.012360406835903089+5.918429292528212E-4i
7007106.306 0.01237934611438875+6.879624169109924E-4i
8008107.207 0.01240097384873408+7.829554908591458E-4i
9009108.108 0.012425198712354842+8.766862477062554E-4i
101 0.012306987852045518+9.955546191163225E-9i
please help me solve this problem.

Answers (1)

Walter Roberson
Walter Roberson on 21 Apr 2018

Microsoft Excel does not support complex numbers by default. You need to enable the Analysis Toolpak in order to create complex numbers -- without that, anything you enter in complex form is just considered to be a text string.

I see that writetable() from MATLAB drops complex components as it writes, so it is not possible to just use the work-around of writetable() to get complex data into a form that can be read back.

I happen to be using Excel for Mac 2011. It turns out that the Analysis add-on is not available for that; they refer me to the third-party xlstat package, which would be a minimum of $US295 dollars per year (I do not qualify as academic.) And that is minimum -- there are premium add-ons and it is not clear which of those would be needed to support complex numbers.

I would suggest to you that you simply make the complex component a third column in the xlsx file, and put the two columns back together again after reading in the data, by using

U = complex(a(:,2),a(:,3))

Community Treasure Hunt

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

Start Hunting!