Error in matrix to image

1 view (last 30 days)
Oliver Lestrange
Oliver Lestrange on 6 Aug 2020
Answered: sanidhyak on 11 May 2025
Hi community,
I've created a matrix with structures. This structures are antennas.
%Vertical
ant.elevation = Vertical.Elevation;
ant.VertMagnitude = Vertical.Magnitude;
%Horizontal
ant.azimuth = Horizontal.Azimuth;
ant.HorizMagnitude = Horizontal.Magnitude;
%Gain and frequency
ant.freq = Optional.frequency;
ant.gain = Optional.gain.value;
I'm getting an error converting the matrix in image. The error is:
Error using image
There is no elevation property on the Image class.
I am converting the matrix to an image using
im = image(gNB,'CDataMapping','scaled');
It seems like the problem is obvious, the structure has an elevation an the class image isn't able to plot it.
How can I turn this matrix in a image? Is the parameters that I am using in image function a part of the problem?

Answers (1)

sanidhyak
sanidhyak on 11 May 2025
I understand that you are trying to visualize a matrix of structures (representing antennas) using MATLAB’s image function, but are encountering an error.
This issue occurs because the image function expects a 2D numeric or RGB array, while you are passing a structure array (gNB or ant) that contains fields like elevation, magnitude, etc. The image function cannot handle structures directly, hence the error.
To resolve this, you will need to extract a numeric field from your structure (e.g., VertMagnitude) and reshape it into a 2D matrix, if necessary, before visualizing it using imagesc or image” function.
Kindly refer to the following corrected approach:
% Example: Extract Vertical Magnitude and reshape to 2D matrix
VertMagMatrix = reshape([ant.VertMagnitude], height, width); % Replace height and width accordingly
% Display the matrix as an image
imagesc(VertMagMatrix);
colorbar;
title('Vertical Magnitude');
If the data is not in a grid format and is instead a 1D vector, you can use:
bar([ant.VertMagnitude]);
title('Vertical Magnitude');
xlabel('Antenna Index');
ylabel('Magnitude');
This method enables accurate visualization by first converting the structured data into a 2D numeric format compatible with image plotting functions.
For further reference on the image and imagesc functions in MATLAB, kindly refer to:
I hope this helps!

Products

Community Treasure Hunt

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

Start Hunting!