How to add x & y value in the odd and even columns in cell matrix

조회 수: 2 (최근 30일)
I have a cell size, i.e., 1x2; suppose each cell has 100 columns. I want to add x value in all even number columns and y in all odd columns. Please suggest in vectorized solution.

채택된 답변

Mouhamed Niasse
Mouhamed Niasse 2021년 6월 12일
Hello,
Here is what i tried based on my understanding of your question.
Hope it does help you.
x=99;y=99; %choose your constants x and y.
A=rand(100); % A and B are 100x100 arrays, you can also define them as 1x100 arrays.
B=rand(100);
C = {A,B}; % C is a 1x2 cell array
C{1}
C{1}(:,2:2:size(C{1},2)-mod(size(C{1},2),2))=C{1}(:,2:2:size(C{1},2)-mod(size(C{1},2),2))+x;
C{1}
C{2}
C{2}(:,1:2:size(C{1},2)-(~mod(size(C{1},2),2)))=C{2}(:,1:2:size(C{1},2)-(~mod(size(C{1},2),2)))+y;
C{2}

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by