Hello everybody. Here is the issue.. having the array C{1,1} I normally don’t know the exact number of rows. How can I split that matrix in 2 parts?, I can use :
o = (C{1,1}(:,[1:end/2]));
to split the first part, however the second part is not that easy because the number of rows varies at the interior in each ‘C’ array. Thank you.

 Akzeptierte Antwort

Jan
Jan am 23 Apr. 2021
Bearbeitet: Jan am 23 Apr. 2021

0 Stimmen

Data = C{1,1};
Len = size(Data, 2);
Half = floor(Len / 2);
Part1 = Data(:, 1:Half);
Part2 = Data(:, Half+1:Len);
It is not clear to me, what this means: "second part is not that easy because the number of rows varies at the interior in each ‘C’ array"
By the way, 1:x is a vector already. The square brackets are Matlab concatenation operator. [1:x] concatenates 1:x with nothing and is a waste of time in consequence.

6 Kommentare

Fercho_Sala
Fercho_Sala am 24 Apr. 2021
@Jan thank you so much, this is the right answer :)
Fercho_Sala
Fercho_Sala am 24 Apr. 2021
@Jan how I can use the same code to split the following arrays C{1,2},C{1,3} ... etc with the same structure (Part1, Part2) for each one independently? , probably with a loop? Thanks.
Jan
Jan am 25 Apr. 2021
Yes, a loop will solve this:
C1 = cell(size(C));
C2 = cell(size(C));
for k = 1:numel(C)
Data = C{1, k};
Len = size(Data, 2);
Half = floor(Len / 2);
C1{k} = Data(:, 1:Half);
C2{k} = Data(:, Half+1:Len);
end
Fercho_Sala
Fercho_Sala am 26 Apr. 2021
@Jan thanks a lot for your knowledge , it works pretty good. :)
Fercho_Sala
Fercho_Sala am 26 Apr. 2021
Bearbeitet: Fercho_Sala am 26 Apr. 2021
@Jan is it possible to plot each item within 'C1' or 'C2' in a subplot structure (4x4) (of course it will be several independent windows) using the 'imagesc' function with the same loop structure? if so, how could you do it?
Fercho_Sala
Fercho_Sala am 26 Apr. 2021
@Jan any comments?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2020b

Gefragt:

am 23 Apr. 2021

Kommentiert:

am 26 Apr. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by