Answered
How to find the order of the power of A matrix?
A = [1,0,1;1,1,0;1,0,0]; B = A; for n = 2:5 B = mod(B*A,2); if isequal(B,eye(3)) break end end n B

3 years ago | 1

Answered
How to loop over a structure in matlab
As far as I can tell, this is your data structure (for simplicity I will define only two field Names, but the code works for any...

3 years ago | 0

| accepted

Answered
Rebuilding a 3D matrix
A1 = A(:,:,[2,5,7]); A2 = A(:,:,[1,6,10]); A3 = A(:,:,[3,4,8,9]); .. change values B = nan(10,10,10); B(:,:,[2,5,7]) = A1; ...

3 years ago | 1

| accepted

Answered
How to save a vector from each iteration in a loop in a matrix?
Take a closer look at your preallocation. What does SIZE(..) return?: size(230,300) so your preallcoation zeros(size(230,300)...

3 years ago | 1

| accepted

Answered
Cropping several images inside a for delivers empty cells
for K=1:10 % <- uppercase I_{k}=imcrop(I{k},RECT); end % ^ lowercase ^ MATLAB is case-sensitive, so you need to make th...

3 years ago | 0

| accepted

Answered
Reorganization of data in matrix
You could DOWNLOAD Jos' excellent PADCAT: https://www.mathworks.com/matlabcentral/fileexchange/22909-padcat and use it somethi...

3 years ago | 0

| accepted

Answered
How to extract the months from a datetime table?
S = load('DateStamp.mat') T = S.DateStamp; T.month = T.date; T.month.Format = 'MMMM' But I am guessing that your actual goal...

3 years ago | 1

| accepted

Answered
How to save results matrix in multi dimensional matrix?
In general with MATLAB it is easier (even if more verbose) to iterate over indices rather than over data. For example: tV = 25...

3 years ago | 0

Answered
How to read a specially structured data file
fid = fopen('test.txt','rt'); mat = fscanf(fid,'%f',[19,Inf]).'; fclose(fid); display(mat)

3 years ago | 2

| accepted

Answered
How can I convert log(-1) to complex number
log10(-1)

3 years ago | 0

| accepted

Answered
For loop only running once
V = {'empty';'occupied'}; X = isnat(deptime(:,1)); T = V(1+X)

3 years ago | 0

Answered
How to overwrite matrix in txt file with another matrix?
Assuming that the //Events block always occurs last in the text file. Lets start by looking at the content of the two files: ty...

3 years ago | 0

Answered
MATLAB not sorting the text files in order.
You can DOWNLOAD and use my code NATSORTFILES: https://www.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filenam...

3 years ago | 0

| accepted

Answered
60 years of daily data; need to group separately by month and year
The simple MATLAB approach using GROUPSUMMARY and UNSTACK: M = categorical(datetime(1,1,1,"Format","MMM"):calmonths(1):datetime...

3 years ago | 0

Answered
reorder data in a matrix
This code finds all permutations with the minimum absolute difference as you specified here: A = [1,0,0,1,0; 1,1,0,0,0; 0,1,1,0...

3 years ago | 0

| accepted

Answered
FOR loop count to the end but the length of the array is different
"so there is no way to have the output vector with directly length of 5 ?" Of course there are multiple ways to achieve this, h...

3 years ago | 0

| accepted

Answered
How to combine multiple numbers into 1 number?
General solution: R1 = 2; R2 = 4; Zr1 = [0,0,0]; V = [R1,R2,Zr1]; N = 10.^(numel(V)-1:-1:0) * V(:)

3 years ago | 0

| accepted

Answered
Load files from two different folders
Do NOT use ADDPATH or CD or any other messing around with the MATLAB search path just for acessing data files. All MATLAB funct...

3 years ago | 0

| accepted

Answered
how get second derivative of a function with one variable? I keep getting not enough input arguments?
"it seems I did everything according to tutorials" Sort of: you defined a function that works on numeric data, but then you hav...

3 years ago | 0

Answered
Creating a graph of |sin(x)|
fun = @(x)abs(sin(x)); fplot(fun)

3 years ago | 0

| accepted

Answered
How to make random voids with for loop?
Why not just use a loop, something like this (aircode): % ... other model settings S = "e" + (1:10); for k = 1:numel(S) ...

3 years ago | 0

| accepted

Answered
Problem with writing datestr converted date time to a text file alongside other numeric variables
Have a look at this line: meteo = [DateTime(i,:) DOY(i,:) Ta_1_1_1(i,:)-273.15 TA_1_2_1(i,:)-273.15 Ts_1_1_1(i,:)-273.15 Ts_2_1...

3 years ago | 0

| accepted

Answered
Find data after 'matched' regular expresion in a file
The file you uploaded is encoded as UTF-16 LE with a BOM: https://en.wikipedia.org/wiki/UTF-16 https://en.wikipedia.org/wiki/B...

3 years ago | 0

| accepted

Answered
How to iterate over a char array and store them into a separate array?
"I want to be able create an array for each of these data structs ..." The simple approach is to use the structure array which ...

3 years ago | 0

Answered
Please help, I keep getting this error... Error using plot Not enough input arguments.
Rather than fiddling around with text and tickmarks, let MATLAB do it for you: V = [33.677;76.714;69.677;64.800;49.871;59.533;4...

3 years ago | 0

Answered
Concatenate cells of a cell array rows into single cell
Use NUM2CELL: C = [repmat({'a'},3,1), repmat({'b'},3,1), repmat({'c'},3,1), repmat({'d'},3,1)] C2 = num2cell(C,2).'

3 years ago | 0

| accepted

Answered
Save all values of a calculation through a loop in a file
"How can I save all the results for each calculation in the mat file?" The standard, efficient, simple approach is to store the...

3 years ago | 1

| accepted

Answered
How to combine the data from multiple netcdf files and make it one .mat file?
Do not expand/concatenate the data inside the loop! A more robust & efficient approach: concatenate once after the loop: S = d...

3 years ago | 1

Answered
Execution of script as a function is not supported
The problem is that you named the script mix_2d_lp_fonc Then when the script gets to this line: fcn_handles = mix_2d_lp_fonc(p...

3 years ago | 0

| accepted

Answered
Read multiple .mat files and process them
"As you said in my case the variable's name changes on each iteration of the outer loop." With changing variable names you will...

3 years ago | 1

| accepted

Load more