Answered
creating year, month, day in month, hours in a day and minutes in that hour MATRIX for any year (e.g 2016)
T1 = datetime(2016,1,1,0,0,0); T2 = datetime(2017,1,1,0,0,0)-minutes(0.5); V = (T1:minutes(1):T2).'; M = [V.Year,V.Month,V.Da...

5 years ago | 0

| accepted

Answered
why the + sign get invalid use of operator?
Note the difference: 1 + 2 % what MATLAB actually supports 1 .+ 2 % what you used There is no separate array version of the ...

5 years ago | 0

Answered
Add to a vector from loop
The MATLAB way: N = 1:1000000; X = abs(cos(N)) < 1./N; T = nnz(X) % total Z = N(X) % those which pass your condition

5 years ago | 0

| accepted

Answered
Creating a table with matrices and arrays as elements
Lets have a look at the data: S = load('visualOdometryGroundTruth.mat') T = S.groundTruthPoses The curly braces in the 2nd an...

5 years ago | 1

| accepted

Answered
How can I interpolate matrix?
M = [0,0,0,0,31.2117;0,0,0,0,0;0,0,0,0,0;0,0,0,0,0;33.4177,0,33.0571,0,32.2147] [Xi,Yi] = find(M); [Xo,Yo] = ndgrid(1:size(M,1...

5 years ago | 2

| accepted

Answered
How to shift a vector using 'for' loop
Store all of the vectors in one cell array (which they should be anyway): C = {V1, V2, V3, V4 ...}; then all you need is this ...

5 years ago | 0

| accepted

Answered
How do you save values from a for-loop in a vector?
With MATLAB it is almost always better to loop over an index than to loop over data: ml = 100:50:1000; n = numel(ml); z = nan...

5 years ago | 0

| accepted

Answered
join 2 strings together to 1
Your example data (you need to learn the difference between string arrays and character arrays): A = "Biegung_35_"; % scalar st...

5 years ago | 0

| accepted

Answered
How to create a table from a string array as header and a numerical matrix as data?
"How can I create a table with this header and matrix as data and write it to excel with writetable?" M = rand(101,37); % fake ...

5 years ago | 0

| accepted

Answered
Plotting multiple lines on one graph
t = [0,0.000225,0.00045,0.00113]; z = 0:0.001:1; z = z(:); C = (sin(3*pi*z).*exp(-50*(3*pi)^2.*t))-(sin(9*pi*z).*exp(-50*(9*p...

5 years ago | 0

| accepted

Answered
Improve speed reading in a .dat file
Some version of this is probably the fastest you can get: [fid,msg] = fopen('example.txt','rt'); assert(fid>=3,msg) for k = 1...

5 years ago | 0

Answered
Make specific columns of a matrix zero.
A = [1,2,3,4,5,6,7,8,9; 5,8,6,44,8,6,8,7,3; 9,8,7,6,5,4,3,2,1]; b = [1,4,5,9]; out = zeros(size(A)); out(:,b) = A(:,b)

5 years ago | 1

| accepted

Answered
Multiply two terms at a set distance apart from each other in an array
The MATLAB approach: v = arr(1:end-23) .* arr(24:end);

5 years ago | 2

Answered
Save structure in Excel
F = fieldnames(dataset); N = 'myfile.xlsx'; for k = 1:numel(F) T = dataset.(F{k}); writetable(T, N, 'Sheet',F{k}) e...

5 years ago | 0

| accepted

Answered
How to find the following pattern in my Char variable in the workspace?
Assuming no nested curly braces: str = '"costOfRevenue":{"raw":4751000000,"fmt":"4,75B","longFmt":"4.751.000.000"},"totalOtherI...

5 years ago | 1

| accepted

Answered
Dir function with no file extension
Try specifying the fixed part of the filename: S = dir('Data*') and/or removing folder from the output: S = dir('*'); S = S(...

5 years ago | 0

| accepted

Answered
Why can't Matlab find functions from a project folder within another project folder?
Folders starting with "+" are package folders: https://www.mathworks.com/help/matlab/matlab_oop/scoping-classes-with-packages.h...

5 years ago | 0

| accepted

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

Load more