Answered
Array size goes out of bounds in for loop.
Preallocate! Preallocate! Preallocate! It makes your loops run faster and it avoids this sort of bugs. What the problem is I ...

8 years ago | 1

| accepted

Answered
How can I load in multiple excel spreadsheets, joining on one field?
xlsfile = 'C:\somewhere\somefile.xlsx'); for sheetindex = 1:10 sheettable = readtable(xlsfile, 'Sheet', sheetindex); ...

8 years ago | 0

Answered
Logical indexing: Find row in table by text in column
Comparison of char arrays is *always* done with <https://www.mathworks.com/help/matlab/ref/strcmp.html |strcmp|>, never with |==...

8 years ago | 2

Answered
Get average of all rows in table that match two exact strings
The easiest way: varfun(@mean, yourtable, 'GroupingVariables', {'sub', 'window'}, 'InputVariables', {'mean', 'stdev', 'rms'...

8 years ago | 1

| accepted

Answered
Removing elements and putting them in a different array
I would recommend that you use better variable names. Ones that have meaning. The simplest way to solve your problem is to wo...

8 years ago | 1

| accepted

Answered
How to delete rows based on values in the first columns that not exist in both data sheets?
Note: |x(1:end, 1)| is written more simply as |x(:, 1)|. To answer your question, and *assuming that the countries are only p...

8 years ago | 1

| accepted

Answered
Can I reshape a function handle? Or change the numeric format of a function handle?
There seem to be a lot of confusion in your post. x = @(t) [something] is a *single* function, regardless of the _someth...

8 years ago | 0

| accepted

Answered
How to exclude rows on the basis of specific entries?
It's not clear what you mean by _repeat_. If you mean you want to delete rows whose first four columns contain more than...

8 years ago | 0

| accepted

Answered
A for loop extracting every new variable into column vectors?
[groupid, groupname] = findgroups(ClustSEMdata.ChElem_Indicator); elements = splitapply(@(v) {v}, ClustSEMdata.ChElem, grou...

8 years ago | 0

Answered
Calculating the mean of a mean
mean(cellfun(@(m) mean(m(:, 4)), particles))

8 years ago | 1

| accepted

Answered
How to replace random integers with the alphabet (1=A, 2=B, and so on)
An easiest way to generate random integers is to use <https://www.mathworks.com/help/matlab/ref/randi.html |randi|>. As for your...

8 years ago | 0

| accepted

Answered
MATLAB generated MATLAB variable list
Right click in the workspace browser, select save (or simply press CTRL+S instead of these two steps), then select MATLAB Script...

8 years ago | 2

| accepted

Answered
get a subcell from a bigger cell
Use |ind2sub|: a(ind2sub(size(a), f, c)) The result will be 1x3 vector not an arbitrary sized array.

8 years ago | 0

Answered
Matrix dimensions must agree problem
You use <https://www.mathworks.com/help/matlab/ref/strcmp.html |strcmp|> to compare char arrays not |==|. Also note that the...

8 years ago | 1

| accepted

Answered
Need help with deleting and moving files by file type
_I know my if statement (if Extracts(i) '\*.stl') isn't correct_ No idea where you've seen something remotely similar to ...

8 years ago | 0

Answered
Access parent folder when using a directory junction?
_There is a directory junction so Matlab thinks it is in: C:\Users\UserName\Documents\project_folder\sub_folder1\sub_folder2_ ...

8 years ago | 1

| accepted

Answered
using IF and && together
The simplest way to do what you want is to not bother at all with loops at all and use <https://www.mathworks.com/help/matlab/re...

8 years ago | 0

Answered
for loop with multiple inputs
If you use a |for| loop, you need to index |X| and |phi| otherwise you will of course overwrite the previous result. So you coul...

8 years ago | 0

| accepted

Answered
Knuth's Algorithm X (Dancing Links; Exact Cover)
Ok, just read the description of the algorithm on wikipedia. A few comments: the test for emptiness is the first step accordi...

8 years ago | 1

| accepted

Answered
Apply function to two cell arrays element-wise
You're overcomplicating: [h, p, k2stat] = cellfun(@kstest, xdata, CDF, 'UniformOutput', false);

8 years ago | 0

| accepted

Answered
I have a question
If there's only one bucket you're interested in then, sum(mydata >= lowerlimit & mydata < upperlimit) / numel(mydata) If...

8 years ago | 0

Answered
how to get the 1st and the 3rd boundary objects in the binary image
Isn't it structBoundaries([1 3]) ? By the way |structBoundaries| is a very misleading name, implying the variable is...

8 years ago | 0

| accepted

Answered
how can I USE bwlabel command, please.....
Have you got the image processing toolbox? What does ver says? You'd typically get this error if you don't have the t...

8 years ago | 0

Answered
efficient way to work with ~2k variables of size ~400x400x3
_"I cannot keep them in RAM"_ Why not? 400x400x3x2000 is under 8 GB of memory as double. Don't you have that much memory avai...

8 years ago | 0

| accepted

Answered
Vectorize nested for loops
Your example is trivially vectorised: %R2016b or later: isgreater = (a - a.') > N; %any version: isgreater = bsx...

8 years ago | 0

Answered
Divide a dataset into subsets
Even a single loop is not needed. A double loop is a complete waste of time. Assuming R2016b or later, assert(all(marker...

8 years ago | 1

Answered
i don't understand why 'f'' is a undefined function. Whats wrong with this line of code?
I would suspect that line of code is supposed to be fprintf(fid,' Max %f %f %f \n', max(data1)) without the |-| between ...

8 years ago | 3

| accepted

Answered
How can I sort strings using only a piece of them?
Note: when giving examples it really helps if you use valid matlab syntax so * we can just copy/paste your example into matla...

8 years ago | 0

Answered
how to covert this number 1.8287e+03??
I suspect you need to learn about the <https://www.mathworks.com/help/matlab/ref/format.html |format|> function. Note that this ...

8 years ago | 1

| accepted

Answered
How do i Take the argmax of a range of values
The <https://en.wikipedia.org/wiki/Arg_max argmax> is defined for a function, not a range of value, you need to know the |x| tha...

8 years ago | 0

Load more