How to reshape a cell array ?

조회 수: 8 (최근 30일)
Baran Mehrdad
Baran Mehrdad 2018년 9월 24일
댓글: Adam Danz 2018년 9월 29일
Hi , I have a this cells :
I want to reshape them , I want each cell include a 95*1 cells which all 95 data are the same value we have for the cell before reshaping. for example look at row 27 . the value is 5.9410 . I want it to be a 95*1 cell which all of the rows has the value of 5.9410. (pls forget about row 28 and assume that in each row we have a single value)
  댓글 수: 3
Baran Mehrdad
Baran Mehrdad 2018년 9월 24일
the input is 672*1 cell array , which in each row we have a single value . I want it to be 672*1 cell array which in each row we have 95*1 cell array and all 95 data has a same data just like before reshaping.
for example if I have a cell array called X and X{1,1}= 2 .I want it to become X{1,1}= {95*1 cell} . and each of 95 cells has the value of 2 .
Adam Danz
Adam Danz 2018년 9월 24일
The two answers below should achieve this.

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

채택된 답변

Adam Danz
Adam Danz 2018년 9월 24일
Assuming the data stored in ESS_estimated_schedule is a cell array,
cellfun(@(x){repmat(x,95,1)},ESS_estimated_schedule)
  댓글 수: 13
Baran Mehrdad
Baran Mehrdad 2018년 9월 29일
Sorry for taking to long. Actually I did not multiplied any variable by ESS_schedule , I just subtract CT from ESS_schedule and I expect to see ESS_schedule to be a 672*1 cell array which each of it's cells contain 95*1 cells . but as you can see it's just 672*1 cell array and each cell contains only one value.
Adam Danz
Adam Danz 2018년 9월 29일
I think I see the cause of your problem now. It's in this line of your code:
[battery_paramaters,ESS_estimated_schedule{Schedule_index}]=obtain_current_SoC(battery_paramaters,opt_prmt(1),CT{Schedule_index}(1),DCT{Schedule_index}(1),Current_week_actual_load_data_reshape{Schedule_index}(1));
I believe CT{Schedule_index} and Current_week_actual_load_data_reshape{Schedule_index} are vectors and in the line above you are only passing the first element of those vector into obtain_current_SoC(). Remove (1) from your inputs if you want to pass the full vectors into that function.

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

추가 답변 (1개)

Adam
Adam 2018년 9월 24일
편집: Adam 2018년 9월 24일
cellfun( @(x) x + zeros( 95, 1 ), ESS_estimated_schedule, 'UniformOutput', false );
It seems like rather large replication of redundant data, but that line should do it for you.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by