Find corresponding values in different arrays

I have T-array, double, 4x1000.
Example of how it looks.
Also I have a cell array Ready, 4x500.
Example, how it looks.
Each cell is a double array, similar structure.
Example of Ready{1,2}.
My goal is to find correspondence values in both T and Ready.
Data in T(1,:) corresponds to the 1st row in Ready, T(2,:) corresponds to 2nd row of Ready, etc.
The 5th row in every cell (6,7,8,9 in the example) corresponds to the column # in T.
How do I fill out the sixth row in Ready with corresponding numbers from T? For example, Ready {1,2} means that we need to look at the values in the 1st row in T. And corresponding values in T will be 10, 12, 14, 16, which I want to write dowin in sixth row in Ready.
Could you please help me with this?

4 Kommentare

Are all the values in T integers? Can you attach T and Ready in a .mat file so people can try things?
CheshireM
CheshireM am 29 Sep. 2021
Bearbeitet: CheshireM am 29 Sep. 2021
No, it's just the begining of T. Most of the values are like 74.66667.
Thank you very much!
CheshireM
CheshireM am 30 Sep. 2021
@Image Analyst Do you have advice with what I should start with?
CheshireM
CheshireM am 30 Sep. 2021
@Kevin Holly Maybe you will have an idea or advice. Thank you!

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Kevin Holly
Kevin Holly am 30 Sep. 2021
Bearbeitet: Kevin Holly am 30 Sep. 2021

0 Stimmen

To be clear, you want to replace the sixth row of read{1,2} with the first row of T?
If so, here it is for the specific example:
Ready{1,2}(6,:) = T(1,1:size(Ready{1,2},2));
Now, let's do if for every cell.
for i = 1:size(Ready,1)
for j = 1:size(Ready,2)
Ready{i,j}(6,:) = T(i,1:size(Ready{i,j},2));
end
end

4 Kommentare

Kevin Holly
Kevin Holly am 30 Sep. 2021
Bearbeitet: Kevin Holly am 30 Sep. 2021
I noticed that the rows in T were longer than the rows in the cells in Ready. I read the row of T up til the length of Ready's row. Let me know if this is what you wanted.
CheshireM
CheshireM am 30 Sep. 2021
@Kevin Holly Thank you for your reply!
If you look at Ready{1,2}, 5th row - you will see 6, 7, 8, 9 - that's the # of columns in T(1,:), which values need to be taken, and it's 10, 12, 14, 16. For example, if we will randomly take Ready{2,100}, the 5th row will be 626 627 628 629 630 631 632 633 634 635 636 637, which are also the # of columns but already in T(2,:). And it's the values (338 338.166666700000 339 339.166666700000 340 340.166666700000 341 341.166666700000 342 342.166666700000 343 343.166666700000), that need to be inserted on the 6th row of Ready{2,100} .
Kevin Holly
Kevin Holly am 30 Sep. 2021
Bearbeitet: Kevin Holly am 30 Sep. 2021
ah, I got it now. The Ready{2,100} example helped a lot. Here you are:
for i = 1:size(Ready,1)
for ii = 1:size(Ready,2)
if ~isempty(Ready{i,ii})
Tcolumns = Ready{i,ii}(5,:); %Get columns values that will be used
index = 1:length(Tcolumns); %Get index of previous array because we will remove the ones corresponding to NaNs
index = index(~isnan(Tcolumns)); %Get rid of index values where Tcolumns = NaN
Tcolumns = Tcolumns(~isnan(Tcolumns)); %Get rid of NaNs in Tcolumns
Ready{i,ii}(6,index) = T(i,Tcolumns); %Fill in row 6 of Ready
end
end
end
CheshireM
CheshireM am 1 Okt. 2021
It works perfectly! Thank you! I also learnt a lot about arrays from your answer!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by