Indexing between numerical and cell arrays

Hi,
I have the below three variables that originally come from numerical and raw outputs from reading a spreadsheet using the xlsread function. The third variable ('NumcCrop") is a subset of "Numc" that was created by removing rows where selected columns had NaN values. I would like to truncate the first variable ("SubRaw") in the same way so that I can extract the names from column two relating to the subset identified in the third variables.
I can't simply remove the rows in the same way as I did to create ('NumcCrop") as the 'raw' output when reading the file only has NaNs for empty cells, whereas the "Numc" variable has NaNs for all non-numerical elements.
It seems like something that should have a simple solution but I have been running into issues with incorrect or inconistent data types when trying to convert the cell arrays into something where they can be indexed or concatenated together. I've tried various cellfun methods including find and ismember but none seem to work.
Thanks a lot!

4 commentaires

Jan
Jan le 12 Oct 2022
Please post the current code. It is easier to expand the code, than to guess the details based on the description of the purpose of the code.
Ben
Ben le 12 Oct 2022
Modifié(e) : Ben le 12 Oct 2022
Apologies - as is typical I discovered a somewhat shorter and simpler solution within a couple of hours of posting this by using a different approach (despite being stuck on the problem for a few days). I managed to generate a logical vector and then apply it to the cell. The code is below:
%Idenitfying rows that correspond to the chosen columns
NanR = isnan(num(:,[3 6 11 12 13]));
NanRFull = NanR(:,1) | NanR(:,2) | NanR(:,3) | NanR(:,4);
NanRFull_Rev = ~NanRFull;
%Use identified rows to index the cell array
SubRaw = raw(2:320,:);
Select_Raw = SubRaw(NanRFull_Rev,:);
VolcNames_Subset = Select_Raw (:,2);
labels = VolcNames_Subset;
Stephen23
Stephen23 le 12 Oct 2022
@Ben: please upload a sample data file by clicking the paperclip button.
Most likely you should be using READTABLE et al.
dpb
dpb le 12 Oct 2022
"...originally come from numerical and raw outputs from reading a spreadsheet using the xlsread function."
And, as @Stephen23 notes, there's the root of all your trouble--using the deprecated xlsread function instead of readtable

Connectez-vous pour commenter.

Réponses (0)

Question posée :

Ben
le 12 Oct 2022

Commenté :

dpb
le 12 Oct 2022

Community Treasure Hunt

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

Start Hunting!

Translated by