how to polar plot excel data in 2D?

7 views (last 30 days)
Mervyn Ang
Mervyn Ang on 7 Mar 2023
Commented: Benjamin Kraus on 8 Mar 2023
Hello everyone, I was tasked to plot a 2-D polar plot of an antenna gain using data sheets from excel. However by executing the code, I received the error "Index in position 2 exceeds array bounds. Index must not exceed 1." I was supposed to use data from box H2 to H26 for this segment of the excel sheet.
I'm not the best coder, but here is my code. Please help me if possible
clc;
clear all;
M = xlsread('AntennaA.xlsx', 'H2:H26');
patternCustom(M(:,3),M(:,2),M(:'1),'CoordinateSystem','rectangular','Slice','theta','SliceValue',M);
title('2D Antenna A Phi Bandwidth')

Answers (1)

Benjamin Kraus
Benjamin Kraus on 8 Mar 2023
Your current code:
M = xlsread('AntennaA.xlsx', 'H2:H26');
Is only returning a single column of your matrix (column "H").
The resulting matrix is 26 rows and 1 column.
You are then indexing into the matrix like this:
M(:,3),M(:,2),M(:1)
That asks for the third, second, and then first columns of the matrix, but there is only one column.
The error you are getting is telling you that your index ("3" and "2") is larger than the size of the matrix ("1").
I assume you also need to read at least two other columns, so you have three columns to plot.
Some options:
  • Call xlsread multiple times to read each column.
  • Change the range (or stop specifying a range) to read the entire table or more columns at once.
As xlsread is no longer recommend, you may also want to switch to using readtable instead.
tbl = readtable('AntennaA.xlsx');
M = table2array(tbl(:,2:end));
el = 0:15:180;
patternCustom(M, 90-el, tbl.Azimuth);
  2 Comments
Mervyn Ang
Mervyn Ang on 8 Mar 2023
Edited: Mervyn Ang on 8 Mar 2023
Thank you! I tried it and it gave me a 3D figure instead. How do I make it into 2D?
For the excel sheet, I only need to plot figures for the column H and A. How should I modify the code to only limit it to these 2 columns?
Benjamin Kraus
Benjamin Kraus on 8 Mar 2023
The data in tbl includes both the columns A (labeled Azimuth) and H (labeled Elevation90deg).
Plotting them involves calling plot on those two variables:
plot(tbl.Azimuth, tbl.Elevation90deg)
If you have a recent version of MATLAB (R2022a and newer) you can also plot directly from the table:
plot(tbl,'Azimuth', 'Elevation90deg')

Sign in to comment.

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!