Double conversion to use prctile function
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alexander Guillen
am 15 Sep. 2022
Kommentiert: Star Strider
am 16 Sep. 2022
Instead of evaluating column by column . I include a for loop so I can use the cell2mat function to convert from double to whatever data type the prctile function uses. However, after the for loop, I get an error message:
"Error using double
Conversion to double from cell is not possible.
Error in prctile (line 55)
x = double(x);
Error in E99 (line 45)
P = prctile(Model_mat(1,:),(99))"
But if I individually convert the column with the cell2mat function- the percentile function works fine.
% This is column by column
Model_mat1 = cell2mat(Model(1,:));
Model_mat2 = cell2mat(Model(2,:));
Model_mat3 = cell2mat(Model(3,:));
Model_mat4 = cell2mat(Model(4,:));
Model_mat5 = cell2mat(Model(5,:));
Model_mat6 = cell2mat(Model(6,:));
Model_mat7 = cell2mat(Model(7,:));
Model_mat8 = cell2mat(Model(8,:));
Model_mat9 = cell2mat(Model(9,:));
Model_mat10 = cell2mat(Model(10,:));
% This is the for loop
for i = 1:length(Model)
%Model_mat{i,:} = cell2mat(Model(i,:));
%Model_mat{i,:} = int64(Model(i,:));
Model_mat{i} = cell2mat(Model(i,:));
end
% This iis the syntax for the percentile
P = prctile(Model_mat(1,:),(99))
Any help would be appreciated.
1 Kommentar
Rik
am 15 Sep. 2022
What exactly is your question? You seem to have a cell array of some sort, but you want the percentile function to do that conversion for you?
It would all be easier to understand if you attach your data to the question.
Akzeptierte Antwort
Star Strider
am 15 Sep. 2022
I am not certain what ‘Model’ is, however if it resembles this array, indexing into it as a cell array is straightforward —
Model = mat2cell(randn(10), ones(1,10),10)
for k = 1:size(Model,1)
P(k) = prctile(Model{k,:},99); % Loop Approach
end
P
P = prctile(cell2mat(Model),99,2) % Matrix Approach
The loop approach would likely be appropriate if all the rows are not the same lengths. Otherwise, the matrix approach is likely more efficient.
.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays 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!