필터 지우기
필터 지우기

want to use output matrix obtained for every iteration of a for loop in another for loop.

조회 수: 1 (최근 30일)
hi, i am developing a code where i have 2 functions: the first function gives me a smaller matrix 'k'.
i want to obtain this 'k' matrix for every iteration.
then i want to add these smaller matrices into a larger one, for that i am using the second for loop.
can anyone please guide me on how i can save each 'k' matrix after every iteration, and then use the 'k' matrices and add them to a larger matrix 'K'?
  댓글 수: 6
Torsten
Torsten 2024년 4월 15일
posr = 4;
posc = 3;
m = rand(6);
M = zeros(120);
M(posr:posr+5,posc:posc+5) = m
M = 120x120
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5457 0.9695 0.6962 0.8960 0.2307 0.4787 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.4676 0.2877 0.9645 0.1411 0.8091 0.1535 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.7857 0.8168 0.4157 0.1047 0.8180 0.2973 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.4923 0.7581 0.6293 0.9764 0.0582 0.7979 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1755 0.0105 0.4215 0.0759 0.2622 0.8527 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5153 0.6940 0.0167 0.7548 0.9984 0.7890 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

댓글을 달려면 로그인하십시오.

채택된 답변

the cyclist
the cyclist 2024년 4월 14일
Here are two possibilities:
% Save into cell arrays
nsmall = 4;
mcell = cell(nsmall,1);
for k = 1:nsmall
mcell{k} = rand(3); % Note curly brackets, to save as *contents* of the cell
end
% Save each matrix as a "slice" of a three-dimensional array
nsmall = 4;
m3d = zeros(3,3,nsmall);
for k = 1:nsmall
m3d(:,:,k) = rand(3); % Saving each slike
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by