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 件のコメント

Jos (10584)
Jos (10584) 2018 年 9 月 24 日
This is a little confusing. Can you give a very small example of the input and expected output?
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 日

0 投票

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 月 24 日
actually now I checked and saw my input is not a cell array it's a Mat. but I want to become cell with the properties I've said
Adam Danz
Adam Danz 2018 年 9 月 24 日
編集済み: Adam Danz 2018 年 9 月 24 日
Then you must make one small change - use num2cell()
cellfun(@(x){repmat(x,95,1)},num2cell(ESS_estimated_schedule))
Stephen23
Stephen23 2018 年 9 月 24 日
編集済み: Stephen23 2018 年 9 月 24 日
Simpler would be to use arrayfun, then you don't need num2cell.
Baran Mehrdad
Baran Mehrdad 2018 年 9 月 24 日
tnx
Adam Danz
Adam Danz 2018 年 9 月 24 日
Stephen's suggestion:
arrayfun(@(x){repmat(x,95,1)},ESS_estimated_schedule)
Baran Mehrdad
Baran Mehrdad 2018 年 9 月 24 日
another question : look this is CT :
and this is Current_week_actual_load_data_reshape :
but when I do this : CT - Current_week_actual_load_data_reshape the answer is like this :
why ? I want the answer to be a 672*1 cell array which each cell contain a 95*1 cell array just like CT and Current_week_actual_load_data_reshape
Adam Danz
Adam Danz 2018 年 9 月 24 日
If CT and Curren_week are cell arrays, then you shouldn't be able to merely subtract them, CR - Current_week. You should get an error
Undefined operator '-' for input arguments of type 'cell'.
Baran Mehrdad
Baran Mehrdad 2018 年 9 月 24 日
編集済み: Baran Mehrdad 2018 年 9 月 24 日
no actually I use a "for" loop and for I=1:672 , I gave CT and Current_week_actual_load_data_reshape as a input to the function I called inside "for" loop(like this : Current_week_actual_load_data_reshape{I}(1) , CT{I}(1)) and in that function I do : CT - Current_week_actual_load_data_reshape
Adam Danz
Adam Danz 2018 年 9 月 24 日
Sorry, I don't follow. Can you post a snippet of code, formatted, so I can understand better what you're doing?
Baran Mehrdad
Baran Mehrdad 2018 年 9 月 25 日

I have this "For" loop , and in this loop , I use Schedule_index= 1:length(current_week_time_stamps) which length(current_week_time_stamps)=672 . and then I call CT and DCT and Actual_load_data_reshape in Obtain_current_SoC function .

 for Schedule_index=1:length(current_week_time_stamps)
     Schedule_index
load_prediction_kw= Current_week_predictions{Schedule_index};
[opt_prmt]=update_optimization_paramters(opt_prmt,load_prediction_kw,battery_paramaters, Current_week_actual_load_data);
ESS_estimated_schedule{Schedule_index}=zeros(95,1);
CT{Schedule_index}=zeros(95,1);
DCT{Schedule_index}=zeros(95,1);
[ESS_estimated_schedule{Schedule_index}, Estimated_SoC{Schedule_index},CT{Schedule_index},DCT{Schedule_index},K{Schedule_index},H{Schedule_index},Answer_all]=obtain_ESS_schedule(load_prediction_kw, battery_paramaters, opt_prmt);
[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));
 [Current_week_actual_load_data]= update_net_load(Schedule_index,Current_week_actual_load_data,ESS_estimated_schedule);
    end

and this is Obtain_current_SoC :

function  [battery_paramaters,ESS_estimated_schedule]=obtain_current_SoC(battery_paramaters,time_slot_duration,CT,DCT,Current_week_actual_load_data_reshape)
current_SOC=battery_paramaters(6);
if Current_week_actual_load_data_reshape < CT 
  ESS_schedule = CT - Current_week_actual_load_data_reshape ;
  current_SOC=current_SOC+battery_paramaters(3)*time_slot_duration*ESS_schedule ;
else
  ESS_schedule = Current_week_actual_load_data_reshape - DCT ;
  current_SOC=current_SOC+ (1/battery_paramaters(3))*time_slot_duration*ESS_schedule ;
end
battery_paramaters(6)=current_SOC;
ESS_estimated_schedule=ESS_schedule ;
end

where CT - Actual_load_data_reshape and Actual_load_data_reshape - DCT happens.

Adam Danz
Adam Danz 2018 年 9 月 25 日
編集済み: Adam Danz 2018 年 9 月 29 日
In your for-loop you define
CT{Schedule_index}=zeros(95,1);
DCT{Schedule_index}=zeros(95,1);
and then you immediately overwrite it via the obtain_ESS_schedule() outputs. Why fill CT{Schedule_index} with zeros?
In any case, if I understand your problem correctly, you expect ESS_schedule to be a vector the same length at CT and Current_week_actual_load_data_reshape (that variable name is way too long). The first thing to check during debugging is whether or not that is true.
The second thing to check is the size of all variables multiplied by ESS_schedule. If you are multiplying two vectors and expect the output to be a vector of the same length containing a piecewise product of the other vectors, they must be the same shape. Here's an example.
% row * column
[1 2 3] * [1;2;3]
ans =
14
% row * row (note the dot!)
[1 2 3] .* [1,2,3]
ans =
1 4 9
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 日

0 投票

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.

カテゴリ

質問済み:

2018 年 9 月 24 日

コメント済み:

2018 年 9 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by