Invalid Data Type Specified - matlab

'
Hello, I am trying to write a for loop that will search through my one-column array for the symbol "[]" or an empty numeric array. However, I keep getting this error when I search for [] : "Abnormal exit: Invalid data type specified. Data type can be Advisor.Element objects or character vector." I really have no idea why this is happening. When I search for a value like "1" or "2", it seems to work.
for x = 1:1:n
if(names_en{1,x} == "[]")
display(new_block_name_enable{x,1}); % finds [] and displays location
end
end

Related

Error by using eval in function in MATLAB

I have the following MATLAB function:
function getDBLfileL1(pathInput,Name_file,folderName)
DBL_files=dir([pathInput,'/*.DBL']); %get DBL files
fprintf('Reading DBL files ... ')
for i = 1:length(DBL_files) %loop through all DBL files
[HDR, CS]=Cryo_L1b_read([pathInput,'/',DBL_files(i).name]); %read data with ESA's Cryo_L1_read function
Coord{i}.LAT_20Hz=CS.GEO.LAT; %store values to struct
Coord{i}.LON_20Hz=CS.GEO.LON;
Coord{i}.BoundingBox_StartLATLON_StopLATLON=[HDR.START_LAT*10^-6,HDR.START_LONG*10^-6,HDR.STOP_LAT*10^-6,HDR.STOP_LONG*10^-6];
Coord{i}.FileName=[pathInput,'/',DBL_files(i).name];
end
eval([Name_file '= Coord;']);
save(['output/',folderName,'/',Name_file,'.mat'],Name_file,'-v7.3')
fprintf('done\n')
end
And it is called in the following:
getDBLfileL1(pathInput,[folderNames{i},'_',folderNames1{j}],folderNames{i}); %read Data from DBL file
The Value of Name_file is '2011_01', and I get the following error:
eval([Name_file])
Error: Invalid text character. Check for unsupported symbol, invisible character, or pasting of non-ASCII characters.
Does anyone know why this error occur or how I can change the file, that I can replace the eval() function?
Thanks a lot in advance!
If I got it right, you are trying to evaluate '2011_01= Coord;' , which means that you are assigning Coord into a variable called 2011_01, and variable names cannot start with numbers

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)
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}];

Problems Accessing Cell Array Items Within a GUI List - Matlab

I have a GUI handle list_h that is populated using a variable named tracks which is a [1xN] cell array. Since, each string within the list_h is assigned a value from 1:N I have been able to devise a for loop that can check which item has been selected from list_h, which works fine.
I was hoping I could extend upon this and be able to select an item from my list_h and be able to extract the string using the String property within list_h, but I am getting an error:
Undefined function 'eq' for input arguments of type 'cell'.
Error in guiPlay (line 13)
if i == list_value
Error while evaluating uicontrol Callback
I was also hoping I could get the full path to each item in list_h, since each item is a reference to an actual .wav file located on my hard drive? I figured this would be a case of concatenating the each item with its corresponding path if this is possible?
Here is the callback function that attempts to extract each list item's string:
function guiPlay(play_toggle_h, evt, list_h)
global predict_valence
button_value = get(play_toggle_h, 'Value');
list_value = set(list_h, 'Value');
N = length(predict_valence);
if button_value == 1
set(play_toggle_h, 'String', 'Pause');
for i=1:N
if i == list_value
track = get(list_h, 'String');
disp(track)
end
end
elseif button_value == 0
set(play_toggle_h, 'String', 'Play');
end
Just for debugging I have used the disp function to display the item.

Iterating Over Unique Values in Matlab

I've been trying to follow this answer in order to obtain unique strings from a given cell array. However, I'm running into trouble when iterating over these values. I have tried for loops as follows:
[unique_words, ~, occurrences] = unique(words);
unique_counts = hist(occurrences, 1:max(occurrences));
for a=1:numel(unique_words)
word = unique_words{a}
count = unique_counts{a}
result = result + a_struct.(unique_words{a}) + unique_counts{a}
end
When trying to reference the items like this, I receive the error:
Cell contents reference from a non-cell array object.
Changing the curly brackets to round brackets for unique_couts yields the error:
Reference to non-existent field 'N1'.
Changing both unique_words and unique_counts to round brackets yields:
Argument to dynamic structure reference must evaluate to a valid field name.
How am I to iterate over the results of unique?
unique_words is a cell array. unique_counts is a vector. So unique_words should be accessed using curly brackets and unique_counts using round ones. The error that you are getting in this case is related to the a_struct (which is not defined in the question) not having the corresponding field, not the access method.

Looping through documents in matlab

I am attempting to loop through the variable 'docs' which is a cell array that holds strings, i need to make a for loop that colllects the terms in a cell array and then uses command 'lower' and unique to create a dictionary.
Here is the code i've tried sp far and i just get errors
docsLength = length(docs);
for C = 1:docsLength
list = tokenize(docs, ' .,-');
Mylist = [list;C];
end
I get these errors
Error using textscan
First input must be of type double or string.
Error in tokenize (line 3)
C = textscan(str,'%s','MultipleDelimsAsOne',1,'delimiter',delimiters);
Error in tk (line 4)
list = tokenize(docs, ' .,-');
Generically, if you get an "must be of type" error, that means you are passing the wrong sort of input to a function. In this case you should look at the point in your code where this is taking place (here, in tokenize when textscan is called), and doublecheck that the input going in is what you expect it to be.
As tokenize is not a MATLAB builtin function, unless you show us that code we can't say what those inputs should be. However, as akfaz mentioned in comments, it is likely that you want to pass docs{C} (a string) to tokenize instead of docs (a cell array). Otherwise, there's no point in having a loop as it just repeatedly passes the same input, docs, into the function.
There are additional problems with the loop:
Mylist = [list; C]; will be overwritten each loop to consist of the latest version of list plus C, which is just a number (the index of the loop). Depending on what the output of tokenize looks like, Mylist = [Mylist; list] may work but you should initialise Mylist first.
Mylist = [];
for C = 1:length(docs)
list = tokenize(docs{C}, ' .,-');
Mylist = [Mylist; list];
end