Answered
matlab reads only first part of big textfile
Although the lines have differing lengths in these badly formatted files, we can observe: each line consists of the same block ...

4 years ago | 0

Answered
How to write my for loop data into an array
Maxes = cell(1,grp); for k = 1:grp .. Maxes{k} = max(Array); end Maxes = vertcat(Maxes{:}); % optional

4 years ago | 0

Answered
string text manipulation - adding data based on previous data in the string
T = 'Time,<Message_CMD>element1,<other_meesage>elemenX,<Message_CMD>element2,<Message_RPT>element3' U = regexprep(T,'([A-Z]+)>(...

4 years ago | 0

| accepted

Answered
How to populate a tree with a struct with different depth?
https://www.mathworks.com/matlabcentral/fileexchange/42487-struct2tree

4 years ago | 0

| accepted

Answered
Problem with indexing a series of ranges
Use MAX's "linear" option: M = randi(9,5,7) [V,X] = max(M, [], 'linear') To be robust you should also specify the dimension: ...

4 years ago | 0

| accepted

Answered
Hi, I want to eliminate duplicates in a cell array in Matlab
T = {[1,2,5], [1,2,5], [1,3,5], [1,4,5], [2,4,5], [4,6]} for ii = numel(T):-1:2 for jj = 1:ii-1 if isequal(T{ii},...

4 years ago | 0

Answered
How to get the number in the cell containing the letter and space
No indirect, fragile, round-about conversion to other data classes is required. Here are two direct approaches: a = {'AABB 0100...

4 years ago | 1

| accepted

Answered
Splitting columns based on comma
raw.Position = {'';'';'';'(-6.9, 4.8, 68.4)';'(-8.5, 3.1, 18.0)';'(13.5, 2.5, 70.1)';'';''}; tmp = sscanf(sprintf('%s',raw.Posi...

4 years ago | 0

| accepted

Answered
Delete all repeatation number
a = [1,2,2,3,2,4,5,6,7,8,6]; [c,x] = histc(a,unique(a)); a(c(x)>1) = []

4 years ago | 3

Answered
How do I split a string using a only *single* whitespace delimiter so any multiple whitespaces are also "split"?
Here are a few approaches using regular expressions, note that 'split' vs 'match' etc. may have different behaviors in case of l...

4 years ago | 2

| accepted

Answered
print value in open form
format short G format long G

4 years ago | 0

Answered
converting atan2 output to 360 deg
The simple, robust, and efficient solution is to use MOD: mod(atan2d(Y,X),360)

4 years ago | 6

Answered
Storing elements of product in a row matrix and extracting the nonzero elements
x = 1:3; y = 4:6; z = 7:9; [X,Y,Z] = ndgrid(x,y,z); A = nonzeros(X.*Y.*Z)

4 years ago | 0

Answered
How to converting complex numbers to absolute values?
No need for slow fiddling around with imported text via CELLFUN or evil EVAL. Just specify the delimiter&whitespace and MATLAB ...

4 years ago | 0

| accepted

Answered
assign cell arrays to struct
You could use CELL2STRUCT : fnm = {'hello','world'}; val = {[1,NaN],[1,4,9]}; S2 = cell2struct(val,fnm,2) or a comma-separat...

4 years ago | 0

| accepted

Answered
how to find indices of duplicates in array and save results on a structure
A = [1;5;2;5;3;3;4;1;2;1]; [U,~,X] = unique(A); V = 1:numel(A); C = accumarray(X,V(:),[],@(v){v}); S = struct('value',num2ce...

4 years ago | 0

| accepted

Answered
Logical indexing cell array
That is an inefficient way to store and process that data. Using one numeric array would be simpler and much more efficient: M...

4 years ago | 1

Answered
Can you download individual images from the image labeling app onto an external hard drive?
"but I can't figure out a way to set the hard drive as the folder I want to save my images in" Don't. Do not set/change to oth...

4 years ago | 0

Answered
Help iteration for loop and tables vertcat
Using one cell array will be much simpler (and more efficient) than your approach of numbering the variable names: w = 1:10; % ...

4 years ago | 1

| accepted

Answered
Splitting table text column with multiple delimiters based on parantheses.
S = ["Player collected a YELLOW coin at (-5.5, 10.9, 90.1)";"Access to new world";"New world entered";"Player collected a GREEN ...

4 years ago | 1

| accepted

Answered
How to store multiple output tables in a cell array
With MATLAB it is easier and more versatile to loop over indices, rather than looping over data. This makes it easy to prealloca...

4 years ago | 0

| accepted

Answered
How can I separate the elements of a vector ?
for jj = i(diff(i)~=0) or for jj = unique(i,'stable')

4 years ago | 0

| accepted

Answered
multiplication by taking into account the values when creating a matrix
A = [2,1,4,3;10,15,20,10;20,10,15,20] B = [1,3,4;4,5,6;2,1,4;3,5,1] C = [50;100;25;10] lkp = [10,15,20]; idx = A(1,:); [~,i...

4 years ago | 1

| accepted

Answered
How to read floating point number 5.3246-5 as 5.3246E-5 in text file
str = '9.4345-51.8998772.518305'; tmp = cellstr(reshape(str,8,[]).'); tmp = regexprep(tmp,'(?<=\d)([-+]\d+)$','E$1') vec = st...

4 years ago | 0

Answered
How to make a two-dimensional mask act on a three-dimensional array?
"I wondered if there was any neat trick to do it by array multipication..." A = 9* ones (6,4,3); % create a 3 dimensional array...

4 years ago | 0

| accepted

Answered
How to create a matrix with special block diagonal structure
N = 8; C = arrayfun(@ones,1:N,'uni',0); B = tril(blkdiag(C{:})); spy(B)

4 years ago | 0

Answered
Remove text from CSV data
str = readlines('20220427T131641-2d.csv'); idx = startsWith(str,digitsPattern); writelines(str(idx),'new.csv') Checking: typ...

4 years ago | 0

| accepted

Answered
How can I get my function that calculates distance between data and user input with sort data and closest data set from file
V = [2,5,7]; M = readmatrix('somedata.xlsx') D = vecnorm(M-V,2,2) [X,Y] = mink(D,2) Z = M(Y,:)

4 years ago | 0

| accepted

Answered
In a 6x6 square matrix A, how to select elements in i-th row with A(i,j) ruled out
A = [0,0,-1,1;1,1,0,0;0,0,1,0;1,-1,0,1] B = +diag(diag(A) & ~any(A-eye(size(A)),2))

4 years ago | 0

Answered
convert lower case to upper and upper to lower
str = '123 Hello World!'; str = regexprep(str,'[A-Za-z]+','${char(mod($&-97,64)+65)}')

4 years ago | 1

Load more