Converting cell in double
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Max1234
am 2 Jan. 2023
Bearbeitet: Stephen23
am 3 Jan. 2023
Hey Guys,
i have a 8942x1 cell and want to convert it into a 8942x1 double ? The final product should be look likes this:
[] 0
1 1
[] => 0
[] 0
[] 0
... ...
Thank you very much for your help!
Attached my file:
0 Kommentare
Akzeptierte Antwort
Star Strider
am 2 Jan. 2023
Bearbeitet: Star Strider
am 2 Jan. 2023
Try something like this —
LD = load(websave('ids','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1249257/ids.mat'));
ids = LD.ids
idsd = cell2mat(ids)
idsmt = cellfun(@isempty,ids, 'Unif',0); % Detect Empty Cells
ids(cell2mat(idsmt)) = {0}; % Fill Missing Values With '0'
idsd = cell2mat(ids)
EDIT — Corrected typographical errors.
.
2 Kommentare
Weitere Antworten (1)
Stephen23
am 2 Jan. 2023
Bearbeitet: Stephen23
am 3 Jan. 2023
Simpler and more efficient:
S = load('ids.mat');
ids = S.ids
Method one: robust indexing:
X = cellfun(@isscalar,ids);
V = zeros(size(ids));
V(X) = [ids{X}]
Method two: VERTCAT():
ids(~cellfun(@isscalar,ids)) = {0};
V = vertcat(ids{:})
0 Kommentare
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!