Undefined operator '>' for input arguments of type 'cell'. | MATLAB | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
Undefined operator '>' for input arguments of type 'cell'.
Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
1
October 4, 2016 - 1:53 am
sp_Permalink sp_Print

I have the following code in a matlab visualisation which used to work fine. However in the last few days the data source has had problems and now my matlab code complains "Undefined operator '>' for input arguments of type 'cell'."

 

readChannelID = [150393];

%% Read Data %%

% Read first data variable
power = thingSpeakRead(readChannelID, 'OutputFormat','table' , 'NumDays', 3)

%% Visualize Data %%
dates=datenum(power.Timestamps);
price=power.Price
price(price>2000)=2000

  '-4e-05'
    '0.00014'
    '0.00014'
    '0.00014'
    '0.00014'
    '0.00014'
    '-3e-05'
    '6e-05'

 

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

 

I'm guessing it doesnt like the "-4e-05" type of entry.  If I reduce the time period to exclude these values it runs OK.

What can I do to clean my data so this works properly?

Avatar
Adarsh_Murthy

Forum Posts: 59
sp_UserOfflineSmall Offline
2
October 4, 2016 - 1:02 pm
sp_Permalink sp_Print

You are right, it looks like data represented in exponential format is leading the column to be represented as a string. Couple options to resolve the error:

 

1. Manually convert the data in Price column to double datatype. Here is some example code:

 

readChannelID = [150393];
%% Read Data %%
% Read first data variable
power = thingSpeakRead(readChannelID, 'OutputFormat','table' , 'NumDays', 3)
%% Visualize Data %%
dates=datenum(power.Timestamps);
price = cellfun(@str2num, power.Price);
price(price>2000)=2000 

 

The cellfun() function call is used to apply the str2num() function to all elements of the Price column. You can find more information about cellfun and str2num functions at the following link:

https://www.mathworks.com/help/matlab/ref/cellfun.html

https://www.mathworks.com/help/matlab/ref/str2num.html

 

2. Update your source to send data to ThingSpeak in a non-exponential format.

 

We will look into options to update the thingSpeakRead function to handle exponential data representation.

 

Thanks! 

Avatar
rw950431

Forum Posts: 252
sp_UserOfflineSmall Offline
3
October 4, 2016 - 8:28 pm
sp_Permalink sp_Print

Thanks Adarsh, cellfun() works perfectly.

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online: jacktheripper125, pudderz
24 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

bbruno22

pudderz

Utkya

Poornak26

LindasHed

reddysiva

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee