Answered
List comprehensions vs. functions
b = -30:30; b = b(b<-5|b>5); v = (-1).^b .* 0.2 .* (b+0.1) Python output: %[-5.98, 5.78, -5.58, 5.38, -5.18, 4.98, -4.78, 4....

5 years ago | 0

| accepted

Answered
"Local function name must be different from the script name" error
clear; % !!!!!!!!!! Delete this line !!!!!!!!! function [any, tri, sqr, rect] = main(number_of_sticks) % first line of the file...

5 years ago | 8

| accepted

Answered
How I concatenate two vectors?
Square brackets are the concatenation operator: you already used them to concatenate lots of scalar numbers into two vectors, no...

5 years ago | 1

| accepted

Answered
Indexing arrays of varying dimensionality.
C = num2cell(calc_ind); X = arr(C{:}) https://www.mathworks.com/help/matlab/matlab_prog/comma-separated-lists.html https://ww...

5 years ago | 0

| accepted

Answered
How to create a structure of matrices within a loop
C = {'A','B','C'}; S = struct(); for k = 1:numel(C) S.(C{k}) = whatever end https://www.mathworks.com/help/matlab/matla...

5 years ago | 0

| accepted

Answered
How can I create a vector like this : X = [1, 2, 1, 2 ......
n = 9; v = 2-mod(1:n,2)

5 years ago | 2

| accepted

Answered
Arrange cell content in a specific order
One easy solution is to download my FEX submission natsortfiles: https://www.mathworks.com/matlabcentral/fileexchange/47434-nat...

5 years ago | 0

| accepted

Answered
matlab not recognizing variable defined in switch/case (Undefined function or variable)
The variable go_home is only defined in cases 14, 15, and 16. In all of the other cases it is undefined. You can probably resol...

5 years ago | 0

| accepted

Answered
How can I extract a slice from a multidimensional array?
The trick here is to define a cell array and then use a comma-separated list for the indices. For example: G = rand(7,6,5,4,3,2...

5 years ago | 0

| accepted

Answered
Accessing data in nested structure arrays
a.b(1).c.d = [1,2,3]; a.b(2).c.d = [3,4,5]; a.b(3).c.d = [5,6,7]; Either V = arrayfun(@(s)s.c.d(1),a.b) Or tmp = [a.b.c]; ...

5 years ago | 1

| accepted

Answered
Adding two matrixes with different row numbers.
A = [1,2,3,4,5,6,7,8,9,10; 10,11,12,13,14,15,16,17,18,19; 19,20,21,22,23,24,25,26,27,28]; B = [1,2,3,4,5,6,7,8,9,10; 2,4,6,8,10...

5 years ago | 2

| accepted

Answered
Why am I getting this error when trying to show a cell of an array? "Brace indexing is not supported for variables of this type"
dat is numeric, so you need to use parentheses: hi = dat(5,3) I already explained this in more detail in my response to your c...

5 years ago | 0

| accepted

Answered
How to make the last iteration of a for loop run differently?
It is simpler to just adjust the indices automatically, no IFs required: nmr = size(PT1,1) grp = 7200; nmg = ceil(nmr/grp); ...

5 years ago | 0

Answered
Getting Data from a struct-array with other structs in it, without a loop
Using arrayfun to iterate over the elements of non-scalar structure Post_Processing.RunData: fun = @(s) s.PowerAnalysis.ECP.PF;...

5 years ago | 0

| accepted

Answered
How do I remove all filenames from my cellarray with .m ending, if else how do I save those with .bmp?
Change the DIR call to specify the file extension: filer = dir(fullfile(katalog,'*.bmp')); This is more efficient than getting...

5 years ago | 0

Answered
how to form a new matrix (i.e. B) from two different matrices (i.e. a1, a2) knowing the indices of its origional matrix (indices of a)?
You can use those indices on the left-hand side. For example: a1 = [2,6,12]; x1 = [1,3,6]; a2 = [4,8,10,14]; x2 = [2,4,5,7];...

5 years ago | 1

| accepted

Answered
Problem running an exe with path containing spaces, while saving command output
Specify double-quotes at each end of the path, e.g.: exe_path = '"C:\users\abc\test folder\test.exe"';

5 years ago | 1

| accepted

Answered
Get English version of web Matlab support
As far as I am aware, there is no way to set this in the user account. The language/locale setting is stored in the cookies for...

5 years ago | 0

| accepted

Answered
Sort an Array with sortrows ( ) with two columns
There are probably nicer ways to do this, as this unfortunately changes the data itself. If required, you could use the index ou...

5 years ago | 1

| accepted

Answered
How to save arrays from a loop with variable names using iterator and how to perform element-by-element operations on arrays and save
"How can I incorporate the iterator i into the variable name?" Don't do that. The simpler and much more efficient approach is t...

5 years ago | 1

| accepted

Answered
matrix step shift in each row
A = [1,2,3,4,5]; B = toeplitz(A([1,end:-1:2]),A)

5 years ago | 0

Answered
Producing a NaN only where there is a NaN, zero otherwise
X = [-inf, -1, -eps, 0, realmin, 2, 1+i, pi, flintmax, realmax, inf, NaN]; Y = 0./(X==X)

5 years ago | 4

Answered
Numerical error using the "diff" function
V = [0,0,0,0.2,0.4,0.6,0.7,0.85,1,1,1]; D = diff(V); X = find(ismembertol(D,max(D)))

5 years ago | 0

| accepted

Answered
Cell array indexing question
%% Part A S = load('QuizGrades.mat'); grades = S.grades student_Names = "Student"+(1:14) student_IDs = 101:114; %% Part...

5 years ago | 1

| accepted

Answered
rearrange a matrix into a vector by blocks
M = [1,3,13,15,25,27;2,4,14,16,26,28;5,7,17,19,29,31;6,8,18,20,30,32;9,11,21,23,33,35;10,12,22,24,34,36] V = reshape(permute(re...

5 years ago | 0

| accepted

Answered
extract date from date time command in matlab
You don't need another command, you just need to change the format property: https://www.mathworks.com/help/matlab/ref/datetime...

5 years ago | 1

Answered
Load different mat files using for loop
Assuming that each mat file contains exactly one variable of unknown name, then try this: D = 'D:\ABIDEdataset\Outputs\dparsf\n...

5 years ago | 0

| accepted

Answered
cell indexing, extracting rectangular subset
The simplest (and usually quite efficient) approach is to use a comma-separated list to create one cell array: tmp = vertcat(to...

5 years ago | 0

| accepted

Answered
Computation on arrays using loops
Y = [2.659717,2.656496,2.656496,2.656173,2.662294,2.661328,2.660039,2.620416,2.614295,2.606242,2.600765,2.600443,2.590779,2.5917...

5 years ago | 1

| accepted

Answered
How to load all the data in one folder
"I am wonder why it happened." Because you always load exactly the same file data (note the indexing you used): filename{1,1} ...

5 years ago | 1

Load more