how to polar plot excel data in 2D?

조회 수: 17 (최근 30일)
Mervyn Ang
Mervyn Ang 2023년 3월 7일
댓글: Benjamin Kraus 2023년 3월 8일
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')

답변 (1개)

Benjamin Kraus
Benjamin Kraus 2023년 3월 8일
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
Mervyn Ang
Mervyn Ang 2023년 3월 8일
편집: Mervyn Ang 2023년 3월 8일
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 2023년 3월 8일
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')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by