select a specific element of each matrix in a string
1 view (last 30 days)
Show older comments
talayeh tavangar
on 1 Jun 2020
Commented: the cyclist
on 1 Jun 2020
Hi,
this is my code
K=rand(448);
for i=1:448
g{i}=[0:1:447]';
end
for i=1:448
U{i}=inv(K)*g{i};
end
so U contain 448 element containing 448*1 in each matrix. Now I want to use element(1,1) of each matrix. what should I do?
1 Comment
Codeshadow
on 1 Jun 2020
One way to go about it would be as below:
tmp = [U{1,:}]; % Places all the data from the cell array into a 448*448 matrix.
Solution = tmp(1,:); % Gets the first element of each U.
clear tmp
Hope that helps!
Accepted Answer
the cyclist
on 1 Jun 2020
Edited: the cyclist
on 1 Jun 2020
firstElementOfEachCellOfU = cellfun(@(x)x(1,1),U);
2 Comments
the cyclist
on 1 Jun 2020
Since this particular question has been answered, I suggest you ask this in a new question (and upvote and/or accept useful answers that you have been receiving on prior questions).
More Answers (0)
See Also
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!