Create new vector from 2 differnet cells
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
dpb
am 19 Jan. 2019
Bearbeitet: dpb
am 19 Jan. 2019
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 Kommentare
dpb
am 25 Jan. 2019
Bearbeitet: dpb
am 25 Jan. 2019
- Just adjust the indexing expression upper limit to match what size tells you.
- 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!