Answered
Could someone explain below part of code please ? I do not understand the first part [~,b]
The |~| <https://uk.mathworks.com/help/matlab/matlab_prog/ignore-function-outputs.html ignores the first output> of |min| as you...

9 years ago | 0

Answered
more efficient way of using for loop?
A few things: * Creating your |years| cell array could be achieved more simply with: years = compose('%d', 2003:2014); ...

9 years ago | 1

Answered
Attempted to access cols3(6); index out of bounds because numel(cols3)=5
Well, yes your code is never going to work, you set |i| to iterate from 1 to the numbers of elements in |cols3|, yet you access ...

9 years ago | 1

| accepted

Answered
Is it possible to avoid copy-on-write behavior in functions yet?
First, you've fallen into the trap of premature optimisation. You've decided not to use functions because they may slow your cod...

9 years ago | 6

| accepted

Answered
multiple switch-case, get position value
|switch ... case| (or |if ... elseif ...|) statements are simple to understand and are great for beginners, but are very limited...

9 years ago | 1

| accepted

Answered
Adding the elements of a field of a struct
Most likely, |zDistance| is a *column* vector. When you do output(activityNum).distanceininches = zDistance(startind:end...

9 years ago | 0

Answered
Generating input binary sequences in an order
Like others, I really don't understand the syntax 0-0, 0-7. I get that you've got 8 different possibilities (0 to 7) for choosin...

9 years ago | 0

Answered
How do I convert this string ?
mat2cell(S, 1, B - '0') is probably the simplest way to do it

9 years ago | 3

| accepted

Answered
How do I store data from my loop?
%.. your initialisation code S1 = zeros(1, numel(g) + 1); %create vector to receive all S1 values needs one more elements ...

9 years ago | 0

Answered
Selecting rows with maximum value with consecutive 3 days occurrence
Finding which days go together: daygroup = cumsum([1; days(diff(datetime(Z(:, 1:3)))) > 3]); Then, if you don't want...

9 years ago | 2

| accepted

Answered
Trying to vectorize a column-wise image processing step
Your code is very easy to vectorise because |imgaussfilt| is very happy to operate at once on a stack of 2D images (i.e. a 3D ma...

9 years ago | 0

| accepted

Answered
how can I select matrix values for those cols and rows for which an f(col,row)==true?
[rows, cols] = ndgrid(1:size(A, 1), 1:size(A, 2)); Then, if |f| can operate directly with pairs of matrices, simply: ...

9 years ago | 0

Answered
how to use textscan to split a string containing numbers, NaN and strings with quotes (or not)?
|textscan| always annoys me, it seems to have lots of hidden rules that are not explicitly stated. I would guess the problem is...

9 years ago | 0

Answered
How can I clear persistent variables from a function using only its handle?
Easy: clear(func2str(yourfunctionhandle)) Note that from a design perspective, you'd be better off with a class rather th...

9 years ago | 1

| accepted

Answered
How to select specific columns in a matrix and create a new one
Either newmatrix = yourmatrix(:, yourmatrix(end, :) == 1) Or newmatrix = yourmatrix(:, logical(yourmatrix(end, :)))...

9 years ago | 0

| accepted

Answered
cellVectors = raw(:,[1,14]);//index exceeds matrix dimension
This awkwardly written code assumes that the excel files have at least 14 columns of data in |Sheet1|. Clearly, your file hasn't...

9 years ago | 0

| accepted

Answered
Constructor behaviour in Classes
This is normal behaviour and 'documented' (but extremely hard to find in the doc even when you what you're looking for!) See ...

9 years ago | 2

| accepted

Answered
My perfect number code keeps showing me error
You have the line if (sum == num1) %() not needed. Matlab is not C The only way this line would work is if |sum| is a ...

9 years ago | 0

Answered
Peaks over threshold counting events
If I understood correctly, overthreshold = yourvalues > yourthreshold; overstarts = strfind([0; overthreshold]; [0; 1]);...

9 years ago | 0

Answered
Creating dummy variables from categorical variable
Another shorter vectorised option (possibly no faster than Stephen's, I haven't tested): [~, ~, col] = unique(vec); out ...

9 years ago | 1

Answered
how to read grid data from text file ?
Whoever created that format should be very ashamed. It's a pain to parse. This is a start. I still need to figure out why I'v...

9 years ago | 0

Answered
How to apply Median FIlter To a color image with out using 'rgb2gray' ? Program please.
Just loop over the colour channels: processedimage = zeros(size(yourimage), 'like', yourimage)); for channel = 1:3 ...

9 years ago | 2

| accepted

Answered
putting some matrix in a cell arrays
The best thing to do is <https://uk.mathworks.com/matlabcentral/answers/57445-faq-how-can-i-create-variables-a1-a2-a10-in-a-loop...

9 years ago | 1

Answered
Adding Arrays of cells
There is a reason we keep on saying <https://uk.mathworks.com/matlabcentral/answers/57445-faq-how-can-i-create-variables-a1-a2-a...

9 years ago | 0

| accepted

Answered
[Matlab] The product of three consecutive integers is 778596.Determine what these three integers are
_"I have tried using for loop and while loop"_ Seriously? How would you solve this trivial problem by hand? You'd simply sol...

9 years ago | 0

| accepted

Answered
Is it possible to multiply a cell array with a colomn in a matrix?
A complete guess since you appear to be using a definition of multiplication that is unknown: V = {'R0', 'R1', 'R2', 'M0', ...

9 years ago | 0

Answered
Vectors must be the same length Help
_I desperately need to fix this somehow_ Well, the proper way to fix this is to actually look at what your code is doing by u...

9 years ago | 0

Answered
calculations in levels ( per name and rank)
Use <https://uk.mathworks.com/help/matlab/ref/findgroups.html |findgroups|> and <https://uk.mathworks.com/help/matlab/ref/splita...

9 years ago | 0

Answered
How to extract columns from two different matrices and create a new one (Loop)
Creating numbered variables (or dynamically named variables of any kind) is an *extremely bad idea* that will make them very dif...

9 years ago | 1

| accepted

Answered
how can I reshape and display all the images from matrix
I have absolutely no idea why you're trying to reshape something into a 28x28 matrix in your loop, nor why you iterating for 1 t...

9 years ago | 0

Load more