Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

How can i change the values of entire rows or columns using values of other rows or columns in a 3D matrix with for loops;

1 visualizzazione (ultimi 30 giorni)
for example c(:,:,1)=[ 2 0 3 0 1 c(:,:,2)=[ 3 0 1 0 2 c(:,:,3)=[ 1 0 5 0 9
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 3 0 2] 5 0 3 0 8 ] 6 0 3 0 1 ]
and i want to make using function mean the following matrix:( the values with the are same).
c(:,:,1)=[ 2 2,5 3 2 1 c(:,:,2)=[ 3 2 1 1.5 2 c(:,:,3)=[ 1 3 5 7 9
1,5 2,75 3 2,25 1,5 4 3 2 3.5 5 3.5 3.75 4 4.5 5
1 2 3 2.5 2 ] 5 4 3 5.5 8 ] 6 4.5 3 2 1 ]
the solution i made is the following, but it is not working in a 3D matrix.
[rowsc,columnsc,bathosc]=size(c);
for k=1:bathosc
for i=1:rowsc
for j=1:2:columnsc-1
c(: , j+1, k)=mean([ c(:, j ,k),c(:, j+2 ,k)] ,2);
end
end
end
for k=1:bathosc
for j=1:columnsc
for i=1:2:rowsc-1
c (i+1,:,k)=mean( [c(i,:,k) ; c(i+2,:,k)] );
end
end
end

Risposte (1)

Guillaume
Guillaume il 24 Apr 2019
Modificato: Guillaume il 24 Apr 2019
This works with your example:
c = cat(3, [2 0 3 0 1; 0 0 0 0 0; 1 0 3 0 2], [3 0 1 0 2; 0 0 0 0 0; 5 0 3 0 8], [1 0 5 0 9;0 0 0 0 0; 6 0 3 0 1])
c(c == 0) = NaN; %replace 0s by NaN
c = fillmissing(c, 'linear'); %fill missing values across rows using linear interpolation
c = fillmissing(c, 'linear', 2) %do the same across columns to fill those rows that were originally all 0

Community Treasure Hunt

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

Start Hunting!

Translated by