Dot indexing is not supported for variables of this type
Show older comments
i am trying to run this code but is not working can you please help me with this
%%
%Data Collection and Labeling
clc;
clear all;
labelPoints = {[2,50],[51,80]};
NoOfFailureModes = 2;
estimateRULFlags = [false, true];
path = 'Datasets/';
labels = {[categorical("OFF"),categorical("ON"),categorical("DUCT BLOCKAGE")],[categorical("OFF"),categorical("ON"),categorical("ROTOR IMBALANCE")]};
rawdata = cell(NoOfFailureModes);
data = cell(NoOfFailureModes);
for i = 1:NoOfFailureModes
rawdata{i} = readtable([path 'Dataset' num2str(i) '.csv'],'Delimiter',','); %Read the downloaded csv file
data{i} = dataParsing(rawdata{i},labelPoints{i},labels{i},i); %Parse the rawdata
end
function data = dataParsing(rawdata,labelPoints,labels,dataset)
bias = 44;
noOfDataPoints = length(rawdata.entry_id);
labelPoints = [0 labelPoints noOfDataPoints];
for i = 1:length(labelPoints)-1
Label(labelPoints(i)+1:labelPoints(i+1),:) = labels(i); %Create Labels for the data points
end
j = 1;
if(dataset == 2)
offset = 0;
else
offset = 2000;
end
for i = 1:noOfDataPoints
text1 = strsplit(rawdata.field1{i},',');
text2 = strsplit(rawdata.field2{i},',');
text3 = strsplit(rawdata.field3{i},',');
text4 = strsplit(rawdata.field4{i},',');
text5 = strsplit(rawdata.field5{i},',');
text6 = strsplit(rawdata.field6{i},',');
var = zeros(length(text1)-1,6);
flag = true;
for k = 1:length(text1)-1 %to neglect the last comma, use -1
var(k,1) = str2num(text1{k})-bias;
var(k,2) = str2num(text2{k})-bias;
var(k,3) = str2num(text3{k})-bias;
if(var(k,1) ~= -bias || var(k,2) ~= -bias || var(k,3) ~= -bias ) %Turning the device off and on will reset the first data set to all zeroes
var(k,4) = str2num(text4{k})-bias;
var(k,5) = str2num(text5{k})-bias;
var(k,6) = str2num(text6{k})-bias;
else
flag = false;
break;
end
end
if(flag) %accept a valid datapoint
data.Label(j,:) = Label(i);
data.sno(j,:) = rawdata.entry_id(i) + offset;
data.X(j,:) = [var(:,1);var(:,4)];
data.Y(j,:) = [var(:,2);var(:,5)];
data.Z(j,:) = [var(:,3);var(:,6)];
j = j+1;
end
end
data = struct2table(data);
end
2 Comments
Adam Danz
on 18 Dec 2020
Provide the full error message, tell us what line is causing that error (the line number is included in the error message but we don't see line numbers so just tell us the line), and describe what variables are used in that line (class & size).
Aniket Manjare
on 18 Dec 2020
Accepted Answer
More Answers (1)
Cris LaPierre
on 18 Dec 2020
The error appears to be line 36
text1 = strsplit(rawdata.field1{i},',');
The current error is because the variable field1 contains numeric info. Brace indexing - {i} - is not valid for a vector of doubles. Use parentheses instead.
This will lead to your next error. The function strsplit is for text data. You will get another error:
First input must be either a character vector or a string scalar.
4 Comments
Aniket Manjare
on 19 Dec 2020
Walter Roberson
on 19 Dec 2020
Your code was written for a different file structure and needs to be redesigned. The file has 5 fields per line with the last one being field3. The code assumes that the field* variables are text with comma separators but in the file they are numeric; the code assumes up to field6 but there is only field3 at most.
Without documentation of the purpose of the code, and with only pictures of part of the code, we are not going to be able to advise you.
Aniket Manjare
on 19 Dec 2020
Aniket Manjare
on 20 Dec 2020
Edited: Walter Roberson
on 20 Dec 2020
Communities
More Answers in the ThingSpeak Community
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


