Answered
Remove single quotes around numeric vector
"Do I have to use another function rather than sprintf?" Get rid of SPRINTF(), converting to character does not help you: Rang...

4 years ago | 0

| accepted

Answered
Processing large matrix faster
Why are you using a loop? Use logical indexing: M = readmatrix('Bathymetry_Data.txt'); X = M(:,3)<(-80); coods = M(X,:);

4 years ago | 0

| accepted

Answered
How to get original values from cumulative sum values?
X = rand(1,9) Y = cumsum(X) Z = [Y(1),diff(Y)] max(X-Z) % alomsot zero Because of the accumulated floating point error getti...

4 years ago | 1

| accepted

Answered
"if sum" (how operator "sum" is possible next to "if"...?)
"Next to "if", there should be logic operator" The IF documentation actually states that it must be an expression. It also stat...

4 years ago | 0

Answered
How can I add an index value to an array value?
M = [0.1,0.1,0.1,0.1;0.2,0.2,0.2,0.2;0.1,0.2,0.3,0.4] M = M + (1:size(M,2))

4 years ago | 2

| accepted

Answered
All tables being vertically concatenated must have the same number of variables.
It is not clear to me why you want/need a table anyway. Why not simply concatenate that variable directly?: prm = 'DisplayLengt...

4 years ago | 1

| accepted

Answered
How to load intermediate variable into workspace while using ode45 ?
Here is the neat, easy, robust approach which returns exactly the a values at the exact t and x output values: tspan = 1:100; ...

4 years ago | 0

Answered
use eval to define a variable from table and a name stored as cell
EVAL is anti-pattern red-herring. Avoid EVAL. The actual solution is to use the methods shown in the MATLAB documentation: htt...

4 years ago | 1

Answered
How the change the dimensions of multiple arrays with the cell, Matlab?
a = cellfun(@transpose,a,'uni',0)

4 years ago | 0

| accepted

Answered
How can I use a colormap to color each row in a matrix the same color?
You need to transpose the input matrices, so that PLOT() gets 300*25 matrices: colororder(parula(25)) plot(lon.',lat.','Marker...

4 years ago | 1

| accepted

Answered
For loop to make an array from workspace variables
Much much better approach: rather than messing about with ugly EVAL, you should always LOAD() into an output variable (which is ...

4 years ago | 2

Answered
Casting a number into a categorical array
x = categorical({'one','two','three'}) c = categories(x) y = setcats(categorical({'two','two','three'}),c) d = categories(y) ...

4 years ago | 0

| accepted

Answered
How to save tables as .mat files without having to type the filename manually?
The solution is to use function syntax, not command syntax: https://www.mathworks.com/help/matlab/matlab_prog/command-vs-functi...

4 years ago | 0

| accepted

Answered
Get number from a string
B = 'α -0.966 ° OK 4.000 -15.000 ° 23.000 ° Freiwinkel' C = regexp(B,'[-+]?\d+\.?\d*', 'match') V = str2double(C)

4 years ago | 0

| accepted

Answered
How to find the index of the first element which is greater than a particular value in a matrix for all the columns.
N = 5; M = randi(9,5,7) Method one: CUMSUM and FIND: X = M>N; X = X & cumsum(X,1)<2; [R,~] = find(X) Method two: FIND and ...

4 years ago | 1

| accepted

Answered
Strings are converted to cells during readtable
The simple solution is to specify the TEXTTYPE option when importing: data = table("string1", "string2"); writetable(data, "da...

4 years ago | 5

| accepted

Answered
Local functions are not working in MatLab R2022a
"I select it all and press F9." That will not work. You need to run the script by calling it by name from the command line: >...

4 years ago | 1

| accepted

Answered
fprintf within a for / if environment with crazy behaviour
The file is opened with fopen(fileID,'wt')" Perhaps, but in any case, you did not provide the file identifier to FPRINTF. "Wha...

4 years ago | 2

| accepted

Answered
How to extract hour+minute from DateTime vector ?
D = datetime(2016,4,5,[8;11],43,11) isAMRush = isbetween(timeofday(D),duration(7,45,0),duration(8,45,0))

4 years ago | 0

| accepted

Answered
Error usin .* Too many output arguments. How to save three variables at the same time in a loop?
Do not use separate variables with names Va, Vb, Vc, etc. The name MATLAB comes from "MATrix LABoratory". MATLAB is designed to ...

4 years ago | 1

| accepted

Answered
Remove element in multidimensional cell array
You used the wrong type of brackets. You used curly braces to place an empty array inside one cell. The reason why you wrote tha...

4 years ago | 0

Answered
2020a readtable error when specifying rectangular range
'DataRange','C2:F4', 'VariableNamesRange','C1:F1'

4 years ago | 0

| accepted

Answered
How to remove a range of rows from all nested structures of a parent structure?
s.a.fa = [1,2,3]; s.a.fb = [7,8,9]; s.a.fn = [4,5,6]; s.a s.a = structfun(@(v)v(1),s.a, 'uni',0); s.a

4 years ago | 0

| accepted

Answered
How to extract matches from results of a regexp match
"But the result is a cell array of cells (not sure why):" Summary: you need to use the ONCE option. Explanation: There are two...

4 years ago | 2

| accepted

Answered
How to extract big size of matrix from workspace to editor?
https://www.mathworks.com/help/matlab/ref/mat2str.html

4 years ago | 0

Answered
How to name variables in a loop?
Use a cell array: https://www.mathworks.com/help/matlab/cell-arrays.html n = 100; C = cell(1,n); for k = 1:n .. run your...

4 years ago | 1

| accepted

Answered
Looping with datetime greater and less than 24 hour
The simple and efficient approach is to use REM: a = duration([0; 0; 24; 0; -24], [22; 52; 6; 1; -5], [0; 0; 0; 0; 0]) b = rem...

4 years ago | 0

Answered
Seperate string and number
T = 'ADC1: 123.7834 1.0139'; V = sscanf(T,'ADC1:%f%f',[2,Inf]).'

4 years ago | 0

| accepted

Answered
Loop which Checks Values of Matrix
Forget about loops, learn the MATLAB approach using indexing: c = 1; W = [4,3,5,2,3]; M = [2.7,1.9,0.75,0.16,0.35] X = M>c; ...

4 years ago | 1

| accepted

Load more