Spica
Spica

Reputation: 127

How to find all values greater than 0 in a cell array in Matlab

I want to find and save all values greater than 0 in an array and save them in a variable called "times". How do I do that? And what is the difference between saving the indices of those cells versus the actual values of the cells?

This is what I have tried, but it must be worng because I get the error:

Undefined operator '>' for input arguments of type 'cell'.

clear all, close all

[num,txt,raw] = xlsread('test.xlsx');

times = find(raw(:,5)>0)

Upvotes: 0

Views: 1499

Answers (1)

Erfan
Erfan

Reputation: 1927

To access the contents of a cell you must use {} instead of ():

idx = find([raw{:, 5}] > 0);

But this gives you the index of the cells of raw containing a positive value. If you want the values instead, you can access them and collect them in a numeric array in this way:

times = [raw{idx, 5}];

Upvotes: 0

Related Questions