linearly spacing a nX1 matrix
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Z.khan
el 20 de Ag. de 2019
Comentada: Z.khan
el 20 de Ag. de 2019
Hi!
I have an nx1 matrix. I want to linearly divide the value in each row into 16 columns thus giving me a nx16 linearly spaced matrix.
For a little example let us say I have a=[45; 50] now I want to creat a 2x4 matrix such that the values in consecutive clolumns are linearly spaced and their sum is equal to 45. Could someone help on this one please?
0 comentarios
Respuesta aceptada
the cyclist
el 20 de Ag. de 2019
Editada: the cyclist
el 20 de Ag. de 2019
Your problem is still under-specified, and an infinite number of matrices will meet you conditions. Here is one possible solution:
a = [45; 50];
numberColumns = 4;
aMat = a + [0:numberColumns-1];
aMat = (aMat - mean(aMat,2) + a)/numberColumns;
8 comentarios
the cyclist
el 20 de Ag. de 2019
So, now you've gone from an under-specified problem to an over-specified one.
If you require ...
- start value
- end value
- number of columns
then you cannot guarantee a particular sum.
This code will get you the listed three:
a = [45; 50];
start = [25; 23];
finish = [ 0; 0];
numberRows = size(a,1);
numberColumns = 4;
output = zeros(numberRows,numberColumns);
for ir = 1:numberRows
output(ir,:) = linspace(start(ir),finish(ir),4);
end
output =
25.0000 16.6667 8.3333 0
23.0000 15.3333 7.6667 0
but sum(output,2) = [50; 46]
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!