Answered
Printing matrix to display error message, why?
The error message "Error using printMatrix Too many output arguments" tells us that you tried to call the function printMatrix w...

6 years ago | 0

Answered
Check if connect 4 occurs in matrix
Simple, efficient, and robust using conv2: >> M = [0,0,0,0,0,0,0;0,0,2,1,2,2,0;1,2,2,2,1,1,2;2,1,1,1,2,1,1;2,1,2,1,2,2,2;1,2,1,...

6 years ago | 2

| accepted

Answered
How do I create a new folder each time I run a code?
The main problem is that you are not passing nextname the path of that location, so instead of looking in the location that you ...

6 years ago | 0

| accepted

Answered
how to conver a string to a array or matrix
You can easily avoid evil eval by using str2func: >> a = '[0 1;J 2]'; >> v = 'J'; % comma-separated variables, e.g. 'J,K,L' >...

6 years ago | 0

| accepted

Answered
I have a cell array with arrays of values 0 and I want to clear those
"I keep getting an exception for my for loop.Index exceeds matrix dimensions." You get this error precisely because you are rem...

6 years ago | 0

| accepted

Answered
Converting anonymous function to a matrix
"How can I build up anonymous functions from other anonymous functions" Just call the functions, exactly like you would any oth...

6 years ago | 0

Answered
Is there a right order for input variables in a function?
"Is there a right order for input variables in a function?" Yes: MATLAB function inputs are positional: The 1st input provided...

6 years ago | 0

| accepted

Answered
How to take my output and store it into a 6x6 array
>> board = [1,2,3,4,5,6,7,8,11,12,13,18,29,30,31,34,35,36]; >> out = zeros(6,6); >> out(board) = board; >> out = out.' out =...

6 years ago | 0

Answered
How to Find the specific character between two repeated strings.
>> V = '<NETWORK>CAN</NETWORK> <DESCRIPTION>Despacito</DESCRIPTION> <INITVALUE>0</INITVALUE><FRAME>ADAS_A08SC_FD</FRAME> <DATA>A...

6 years ago | 1

| accepted

Answered
simple way of matrix array resorting
Robust: Q = [A(:),B(:),C(:)]

6 years ago | 1

| accepted

Answered
Cycle counting from 0
>> M = [0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0]; >> D = diff([false;M(:)==0;false]); >>...

6 years ago | 0

| accepted

Answered
Loading Multiple .mat files, but not into structure
"not sure how to do this within a structure though" So now is a good time to learn! Instead of learning the worst way of doing ...

6 years ago | 1

| accepted

Answered
Extract *.mat-Variables with same names from different directories
"A simple 'load' command will give me a strut, which I can't do much with." "Ideally, I'd like a workspace containing all 96 va...

6 years ago | 0

| accepted

Answered
n! permutation matrices
A purely numeric solution without loops: >> I = eye(4); >> M = reshape(I(:,flipud(perms(1:4)).'),4,4,24) M = ans(:,:,1) = ...

6 years ago | 0

Answered
Map between two cell arrays
"All the values of course." Then you cannot use containers.Map: even if you manage to sort out everything else (those numeric i...

6 years ago | 1

| accepted

Answered
Index exceeds Matrix Dimension
Simpler, more robust code: >> N = 20140705001529; % Ugh... dates should not be stored like this! >> S = sprintf('%d',N); >> S...

6 years ago | 0

Answered
How to apply function to certain files in directory
D = 'relative/absolute path to the directory where the files are saved'; S = dir(fullfile(D,'*.raw')); for k = 1:numel(S) ...

6 years ago | 1

Answered
Interval where values are greater than treshold
>> B = find([true;diff(Logic(:))>0]); >> E = find([diff(Logic(:))<0;true]); >> M = [B,E] M = 1 3 7 8 10 ...

6 years ago | 0

| accepted

Answered
count a sequence of 1 or 0
>> M = [0,0;0,1;1,1;1,0;1,1;1,0;0,1;1,1;0,1;0,1] M = 0 0 0 1 1 1 1 0 1 1 1 0 0 1 ...

6 years ago | 1

| accepted

Answered
Why does my code think I want to use the Symbolic Math Toolbox when in reality I want to solve a system of ODEs numerically?
Take a look at these two lines: %% create function handle to euler, which contains ODEs fun=@euler; euler is in the symbolic ...

6 years ago | 0

| accepted

Answered
Elementwise Matrix multiplication with a Vector to get a higher dimension Matrix
"How can I make my Code more efficient?" A2 = bsxfun(@times,A1,reshape(V1,1,1,[])) % for versions >= R2007a A2 = A1 .* reshap...

6 years ago | 2

Answered
How to get the mean of a cell array of matrices
>> out = permute(num2cell(mean(cell2mat(permute(test,[1,3,2])),1),2),[1,3,2]); Checking: >> size(out) ans = 1 1000 ...

6 years ago | 0

| accepted

Answered
I need to convert a number into its column name equivalent
Unfortunately Andrei Bobrov's answer does not really take into account the missing zeros, which means that it leads to a kind of...

6 years ago | 3

Answered
Plot by loading a vector, saved from a different workspace as .mat file(converting struct to vector)
Use a loop, e.g.: D = 'temp'; % path of the folder where the files are saved. N = [10,15,20]; C = 'rgb'; for k = 1:numel(N) ...

6 years ago | 0

| accepted

Answered
regexp help when comparing strings
"Strings which are compared are identical" In general regular expressions are NOT used to compare identical strings (although i...

6 years ago | 1

| accepted

Answered
Generating vector with n elements from a to b with the same incrementation
linspace(a,b,n) https://www.mathworks.com/help/matlab/ref/linspace.html

6 years ago | 0

Answered
a easier way to do vector
"Is there any easier or more efficient way to calculate SF when there is different k?" Do NOT use numbered variables, they are ...

6 years ago | 0

| accepted

Answered
Starting from the year 1697, store all leap years until 2017 in a vector. A leap year is a year which is divisible by 4 but NOT 100 but if the year is divisible by 100 then it must also be divisible by 400 to be considered a leap year.
You made a good start, all you need is to use indexing or concatenation to store the values that you want to keep, e.g.: lpy = ...

6 years ago | 1

| accepted

Answered
How do I get two values of a function when using a loop?
You are only calling the function with one output argument. If the function returns two output arguments and you want both of th...

6 years ago | 1

| accepted

Answered
vectorisation a for loop
Real vectorized code (no loop or arrayfun): eta = exp(-c*abs(bsxfun(@minus,dist,dist(:)))); discrim = 1./sum(eta,1) Or for MA...

6 years ago | 0

Load more