Create new vector from 2 differnet cells

1 回表示 (過去 30 日間)
Rok Recnik
Rok Recnik 2019 年 1 月 19 日
編集済み: dpb 2019 年 1 月 25 日
Hello I have a two cells and I would like to save that data into one vector.
For example:
I have cell: Lok_max (3x2 cell)
and Lok_min(2x2 cell)
If I create vector by hand writing it will be like this:
SOC= [Lok_max{1,1},Lok_min{1,1},Lok_max{2,1},Lok_min{2,1},Lok_max{3,1}];
SOC_time=[Lok_max{1,2},Lok_min{1,2},Lok_max{2,2},Lok_min{2,2},Lok_max{3,2}];
I would like to automatize and I think that I can use for loop.
My idea is:
for interval_max=1:size(Lok_max)
for interval_min=1:size(Lok_min)
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
end
end
I think that I can use 2 for loops. I don't know how to create vector with for loop from cell.
Please help me.
Best regards

採用された回答

dpb
dpb 2019 年 1 月 19 日
編集済み: dpb 2019 年 1 月 19 日
You could use loops, but that's not "the MATLAB way!"...
This also superfically seems like a place cell arrays may be in the way; and I'll use shorter names for brevity and legibility of not having similar-looking names to try to pick out visually --
>> A=reshape(1:6,3,2); % some easy-to make sample data that can still see
>> B=reshape(1:4,2,2)+10; % who's who in the zoo to see where values ended up
N=size(A,1)+size(B,1); % how many rows are in result is total number in each
C(1:2:N,:)=A; % place A in alternate rows from top
C(2:2:N-1,:)=B; % and B alternates but there's a missing row
>> C = % see what's we got...
1 4
11 13
2 5
12 14
3 6
>>
Your desired two vectors are columns 1, 2, respectively.
The above is generic as long as A has one more row than B
  5 件のコメント
Rok Recnik
Rok Recnik 2019 年 1 月 25 日
編集済み: Rok Recnik 2019 年 1 月 25 日
But what If I have the same size of A and B. Until now it works perfect but now I have some data with the sam size cells A and B. Is it possible to automatic dedection if A and B is the same size and if my data started with max or with min? I want to fully automatize this.
dpb
dpb 2019 年 1 月 25 日
編集済み: dpb 2019 年 1 月 25 日
  1. Just adjust the indexing expression upper limit to match what size tells you.
  2. Probably...if the data sections are the sections between the min/max peaks/valleys in the previous plot, then inspecting the first/last section of those and comparing (say) average magnitudes should tell you what you want to know...the noise will dictate how complicated the comparison must be. If push comes to shove, a polyfit(x,y,1) over the whole section and testing the sign of the slope term should be pretty reliable.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by