MATLAB Answers

Divide by 2 every second double column without losing structure of cell array

1 view (last 30 days)
Nik Rocky
Nik Rocky on 18 Jun 2020
Commented: Nik Rocky on 18 Jun 2020
Hello, I have a big cell array, every Cell has 2 columns. Hove can I divide by 2 every second double column without losing structure of cell array?
Test =
1×189 cell array
Columns 1 through 5
{14×2 double} {9×2 double} {3×2 double} {4×2 double} {7×2 double}
Columns 6 through 10
{5×2 double} {8×2 double} {7×2 double} {12×2 double} {6×2 double}
Columns 11 through 15
.......
For example:
1.11 490
1.14 492
1.17 488
1.20 484
to
1.11 245
1.14 246
1.17 244
1.20 242
somethink like this, but its a wrong code
Test{1,:}=Test{1,{:}/2}
Thank you!

  0 Comments

Sign in to comment.

Answers (2)

Deepak Gupta
Deepak Gupta on 18 Jun 2020
Below program should work for your problem:
test = {[10, 15], [20, 30]};
for index = 1: length(test)
test{index}(:, 2) = test{index}(:, 2)/2;
end

Vinayak Mohite
Vinayak Mohite on 18 Jun 2020
Hi Nikita,
I am assuming that you want to divide the second column in the table by 2.
Here is the way to do it.
Test{:, 2} = Test{:, 2}./2

Tags

Community Treasure Hunt

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

Start Hunting!