Answered
Save each pair in container.Map to separate variable in .mat file
"Is there a better way to do this?" Of course, just use the -struct option when calling save. Note that conversion to structure...

5 years ago | 1

| accepted

Answered
how to convert cell array to matrix
Where C is your cell array: M = horzcat(C{:}).'

5 years ago | 0

| accepted

Answered
Convert a cell with structures into a matrix
Rather than inefficiently storing lots of scalar structures in a cell array, you should just use one efficient non-scalar array,...

5 years ago | 0

Answered
Counting the number of the unique value in each row of a matrix without using for loop
M = randi(9,5,7) N = 1+sum(diff(sort(M,2),1,2)~=0,2)

5 years ago | 2

| accepted

Answered
I only need the output from the last iteration
Wrap disp in a suitable if statement, e.g.: if j==N disp(..) end

5 years ago | 0

| accepted

Answered
How to split datetime vector into a numerical Matrix?
M = [t2.Year(:),t2.Month(:),t2.Day(:)] or use the first three columns: M = datevec(t2)

5 years ago | 1

| accepted

Answered
Identify the file number from the folder
D = 'absolute or relative path to where the files are saved'; S = dir(fullfile(D,'R*.bmp')); V = sscanf([S.name],'R%fbmp')

5 years ago | 0

| accepted

Answered
How to find unique values in a matrix without looping over rows
M = randi([0,9],3,13) W = sort(M,2); W(diff(W,1,2)==0) = 0; W = sort(W,2) % optional

5 years ago | 0

Answered
Build matrix of different size column vectors generated inside a for loop
Inside the loop store the vectors in a preallocated cell array. Then after the loop use PADCAT (download required): https://www...

5 years ago | 0

| accepted

Answered
How to extract numeric data between string lines?
str = fileread('02-2021-Clearance-Box005_fort72.txt'); rgx = '(?<=Number of hit cells:\s+\d+\s+)(\d+[^\n]*)'; tmp = regexp(str...

5 years ago | 0

| accepted

Answered
Replacing a numberless string in matrix with a number
Where V is that column: V = ["female";"male";"female";"male";"male";"female"] X = strcmpi(V,"female")

5 years ago | 1

Answered
how to extract an extra variable which is calculated in ode function to main workspace?
Ignore advice that you should use assignin or evalin, because this does not take into account how ODE solvers work, as well as b...

5 years ago | 0

| accepted

Answered
Why does ishghandle(0) alwys return true?
Because the graphics root always exists: https://www.mathworks.com/help/matlab/creating_plots/graphics-objects.html Using zero...

5 years ago | 2

| accepted

Answered
pick elements from a 3d array, based on an indexing matrix
https://www.mathworks.com/help/matlab/ref/sub2ind.html % fake data: nr = 5; nc = 7; np = 3; A = randi(9,nr,nc,np); I = ran...

5 years ago | 0

| accepted

Answered
Loading data from structure, using variable
The most important step is to always load into an output variable (which itself is a scalar structure): S = load(...) % always ...

5 years ago | 2

| accepted

Answered
Sum per 2 elements in vector
A = [1;2;3;4;5;6]; B = A(1:2:end) + A(2:2:end) or more generally: B = sum(reshape(A,2,[]),1).' or B = reshape(A,2,[]).' * o...

5 years ago | 1

| accepted

Answered
Problem outerjoin two tables 20x1 ; 20x8
I don't see why outerjoin is required: newTable = [ArrayTime,ArrayZ]

5 years ago | 0

| accepted

Answered
Matlab round the values and find function can not give the exact result(index)?!
"I used this expression format longE to consider the actual values" format longE does not show the "actual values", it just sho...

5 years ago | 0

| accepted

Answered
Import data from bpmn file into one string/char value Matlab
The simple solution: https://www.mathworks.com/help/matlab/ref/fileread.html str = fileread(...);

5 years ago | 0

| accepted

Answered
Getting extra parameters from ODE45 and the mystery transpose
Using the OutputFcn is a complex way to get the Fs values. The simpler approach is to run the ODE solver normally, and then run...

5 years ago | 0

Answered
Normalizing RGB coordinates in an image
You did not take into account the integer class that you are using. Most likely the image data is uint8, which supports values ...

5 years ago | 0

| accepted

Answered
dynamically save a matrix to a structure
Do NOT use eval for trivial code like this. That approach is slow, complex, inefficient, and not recommended. Rather than messi...

5 years ago | 0

| accepted

Answered
Conditionally select from array of struct by membership of a list in struct element
X(1).Members = [1,2]; X(1).Name = 'Group 1'; X(2).Members = [2,3]; X(2).Name = 'Group 2'; F = @(n)arrayfun(@(s)any(s.Members...

5 years ago | 0

| accepted

Answered
Can I somehow improve performance of str2double?
The fastest conversion uses low-level commands, e.g. sprintf and sscanf. Instead of this: C = {'1.2','3.4','5.6'}; V = str2dou...

5 years ago | 7

| accepted

Answered
How to sort one array based on the order of a second array?
As far as I can tell, the order of Q is irrelevant. A = ["1a","1b","1c","1d","1e","2a","2b","2c","2d","2e"]; % sorted B = ["A1...

5 years ago | 1

| accepted

Answered
Reshape array such that boundaries remain the same
x = [0, 1, 2, 1, 0]; y = [0, 0.5, 1, 1.5, 2, 1.5, 1, 0.5, 0]; xnew = interp1(x,linspace(1,numel(x),numel(y)))

5 years ago | 0

| accepted

Answered
Why am I getting "Array indices must be positive integers or logical values" error?
Consider this indexing: x1(i-j+1) What value does it have on the last iteration of the j loop? (hint: zero). i-j+1 % that ind...

5 years ago | 1

| accepted

Answered
Get unknown variable from mat-file
Given only one variable saved in the mat file: tmpC = struct2cell(load(filename)); myVar = tmpC{1}; Do not worry about the t...

5 years ago | 2

| accepted

Answered
Extracting the numbers from file names and listing them in a column
C = {'Rpma26siatBz 9.500000 Bx 0.000000mT WWait 2.000000Sec.Bzat9.5mT83.png',... 'Rpma26siatBz 9.500000 Bx 100.000000mT WW...

5 years ago | 0

| accepted

Answered
sum contents of array in groups of 10
Where V is your 1x3001 vector: M = sum(reshape(V(1:3000),10,[]),1)

5 years ago | 0

| accepted

Load more