How to change data in a cell array of doubles?

조회 수: 4 (최근 30일)
Graduate Student
Graduate Student 2021년 3월 31일
댓글: Mirthand 2021년 4월 1일
I have attached the variable that I am trying to change. The first column in each double is time. I would like to go through all the trials and fix the time so that it starts from 0, by doing time = time - 1
Time for the first trial (portion).
9.69938400000000
9.74050100000000
9.75054700000000
9.75911600000000
9.76805000000000
9.78226300000000
9.83225600000000
9.86755800000000
9.88683400000000
9.89537800000000
9.90186700000000
9.90746900000000
9.91257600000000

채택된 답변

per isakson
per isakson 2021년 3월 31일
??? "doing time = time - 1" doesn't "fix the time so that it starts from 0"
Try this
>> load('trials.mat')
>> cac = cellfun( @(num) num-[num(1,1),0,0,0,0,0,0], trials, 'uni',false );
>> trials{1}(1:6,:)
ans =
9.6994 0 2673.3 0 4.93 0.41 600
9.7405 0 2673.7 0 10 0.41 600
9.7505 0 2674.1 0 40.91 0.82 600
9.7591 0 2674.5 0 47.96 1.23 600
9.7681 0 2674.9 0 46 1.64 600
9.7823 0 2675.3 0 28.91 2.05 600
>> cac{1}(1:6,:)
ans =
0 0 2673.3 0 4.93 0.41 600
0.041117 0 2673.7 0 10 0.41 600
0.051163 0 2674.1 0 40.91 0.82 600
0.059732 0 2674.5 0 47.96 1.23 600
0.068666 0 2674.9 0 46 1.64 600
0.082879 0 2675.3 0 28.91 2.05 600
>>
Or "doing time = time - 1"
>> cac = cellfun( @(num) num-[1,0,0,0,0,0,0], trials, 'uni',false );
  댓글 수: 5
per isakson
per isakson 2021년 4월 1일
I don't know how to answer.
MATLAB Onramp ...Learn the essentials of MATLAB through this free, two-hour introductory tutorial on commonly used features and workflows....
Do some experiments, e.g.
>> m = magic(3)
m =
8 1 6
3 5 7
4 9 2
>> m - [m(1,1),0,0]
ans =
0 1 6
-5 5 7
-4 9 2
Mirthand
Mirthand 2021년 4월 1일
Thanks! Your example made sense and I'll take a look at the tutorial!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by