Create a triangular matrix

7 visualizaciones (últimos 30 días)
stelios loizidis
stelios loizidis el 2 de Dic. de 2021
Editada: Image Analyst el 2 de Dic. de 2021
Hello,
I have the following issue. I have a matrix A with dimensions 3x500 and I want to calculate the matrix B which is triangular of A. Below is the code I wrote:
% A: 3X500
B=zeros(length(A));
for i=1:length(B)
for j=1:length(B)
B(i,j)=exp(-(A(:,i)-A(:,j).^2)/5);
end
end
The following error occurs:
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is
3-by-1.
How is this problem solved? Your help is important.

Respuestas (1)

Image Analyst
Image Analyst el 2 de Dic. de 2021
Editada: Image Analyst el 2 de Dic. de 2021
You're subtracting the ith and jth column, which gives a whole column (3 values). Then you're trying to stuff those 3 values into a single location at B(i,j). You can't stuff 3 numbers into a position meant for one number. Not really sure what you want to do so not sure how to fix it.
For triangular matrices, see the functions tril() and triu().

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by