- 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.
how to polar plot excel data in 2D?
조회 수: 7 (최근 30일)
이전 댓글 표시
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')
댓글 수: 0
답변 (1개)
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:
tbl = readtable('AntennaA.xlsx');
M = table2array(tbl(:,2:end));
el = 0:15:180;
patternCustom(M, 90-el, tbl.Azimuth);
댓글 수: 2
Benjamin Kraus
2023년 3월 8일
The data in tbl includes both the columns A (labeled Azimuth) and H (labeled Elevation90deg).
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 Center 및 File Exchange에서 Calendar에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!