Answered
Extracting a specific digit from a float w/o floating-point implementation rounding issues
Some people will incorrectly tell you that this is not possible, but in reality there is a simple and efficient solution: >> N ...

6 years ago | 0

| accepted

Answered
How to replace a word with another word in a cell array (case insensitive)
Method one: loop and regexprep: for k = 1:numel(withthis) str = regexprep(str,replaceword,withthis{k},'once','ignorecase')...

6 years ago | 1

| accepted

Answered
How can I add data to an existing array when the dimension do not agree?
Just use indexing to specify how many elements you are allocating to. MATLAB will expand the array to fit: >> B = ['ABC';'DEF']...

6 years ago | 0

| accepted

Answered
cell2mat Error :using cat Dimensions of arrays being concatenated are not consistent.
%P2 = {0,[1;2];0,0}; % test data P2 = Numerical_FourierForce{1,1}; X = cellfun(@(a)isequal(a,0),P2); P2(X) = {[0;0]}; P2 = c...

6 years ago | 0

| accepted

Answered
Breaking data from a large text file into groups
"I just need to determine the group with the highest number of elements and output that list only." So for your example data th...

6 years ago | 1

Answered
How to convert string to datetime format in parquet file format within parquet datastore?
>> D = {'2020/1/1' ;'2020/1/1' ;'2020/1/1' }; >> T = {'00:01:0:0';'00:01:0:60';'00:01:0:320'}; Method one: sscanf and durat...

6 years ago | 0

| accepted

Answered
Sorting specific dates from Datetime array
This is easy using datetime and days: >> vd = linspace(days(-2),days(2),10); >> dt = datetime+vd(:) dt = 12-Jul-2020 00:...

6 years ago | 0

Answered
Sort rows of a matrix based on a specific array
>> [X,Y] = ismember(A(:,1),B); >> [~,Z] = sort(Y(X)); >> T = A(X,:); >> A(X,:) = T(Z,:) A = 3 1 1 2 0 0 ...

6 years ago | 1

| accepted

Answered
How to use metacharacters in combination with cell arrays to build up a pattern for regexp?
"my goal is to get the max index of occurence of the string "22" with no other digits or characters before or after it." I assu...

6 years ago | 0

| accepted

Answered
Why did I get different print format in the output txt file?
"I am wondering why the alignment of columns when using my old Dell are Not as good as those when used my iMac and new dell." T...

6 years ago | 1

| accepted

Answered
Giving a Different Value to Elements of Array
Using numbered variables is a sign that you are doing something wrong. In this case, using indexing would allow you to use a lo...

6 years ago | 0

| accepted

Answered
Accessing the nth dimension in a variable sized multidimensional array
"...how do I get A(1,1,...,1,:) when I don't know how many dimensions A has?" You use a comma-separated list, which you can eas...

6 years ago | 1

| accepted

Answered
Allocating first and last rows from column 2 that correspond to specific criteria in column 1 in a for loop to a new matrix or submatrix
X = [1,0,0,0;1,1,1,0;1,1,1,1;0,1,1,1;0,0,0,1]; N = size(X,2); Y = nan(2,N); for k = 1:N V = find(X(:,k)); Y(:,k) = ...

6 years ago | 0

| accepted

Answered
Not enough input arguments
Exactly as the pdepe documentation explains (and its examples show) you need to provide three function handles as its 2nd, 3rd, ...

6 years ago | 0

| accepted

Answered
Apply a customized function to cell array
D = cellfun(@RemoveZeroColumnsInCSImatrix, C, 'UniformOutput',false);

6 years ago | 0

| accepted

Answered
Reading image in zig zag, and arrange the output matrix in ascending and descending issue
>> A = [5,13;7,13;6,13;4,14;5,14;8,14;5,16;8,16;7,16;9,16;3,20;6,20;8,20;9,20] A = 5 13 7 13 6 13 4 ...

6 years ago | 0

| accepted

Answered
How to replace leading zeroes by spaces with regexprep
>> fun = @(c)regexprep(c,'^0+(?=\d)','${char(double($&)-16)}'); >> out = varfun(fun,T) out = Fun_a Fun_b Fun_c ...

6 years ago | 1

| accepted

Answered
Open multiple .csv files, process and save them in a structure
You need to fix this line otherwise your loop will only iterate once: for i = 1:length(filename) % ^ this must be a col...

6 years ago | 0

| accepted

Answered
Shuffling numbers while keeping identical numbers next to each other
>> A = [1,1,2,3,3,4,6,6,6,6]; >> X = diff(find([1,diff(A),1])); >> C = mat2cell(A,1,X); >> Y = randperm(numel(C)); >> V = [C...

6 years ago | 1

| accepted

Answered
Dynamic call to structure elements
You can trivially access the fields of a structure using this syntax, where F is the fieldname: S.(F) See: https://www.mathwor...

6 years ago | 0

Answered
MATLAB example not working.
Typical reasons why that function might not work: scatteringchanmtx was introduced in R2017b. It will not work with earlier MAT...

6 years ago | 0

| accepted

Answered
How to use varargin and varargout?
As their documentation explains, both varargin and varargout are cell arrays. So if required (e.g. to perform numeric operations...

6 years ago | 1

| accepted

Answered
Data types of arrays in a function
B = int8(A); if any(B(:)~=A(:)) B = A; end Note that this is a more versatile approach because it does not use hard-code...

6 years ago | 0

Answered
Merge specific text files
You will need two loops, the outer loop for M1, M2, etc, and the inner loop for the files R1,R2,R3,...R100, e.g.: D = 'path to...

6 years ago | 0

| accepted

Answered
Who could get all the data in the attached file by the matlab?
>> rgx = '([-+]?\d+\.?\d*([eE][-+]?\d+)?)'; >> str = fileread('tem-001.txt'); >> tkn = regexp(str,[rgx,'\s+',rgx],'tokens'); ...

6 years ago | 0

| accepted

Answered
Trying to create a set of matrixes using a for loop. I have an error on line 23: Array indices must be positive integers or logical values. Basically making matrixes labeled ke1, ke2, ke3...
There are multiple issues with your loop: you are attempting to use invalid indices (e.g. 0, pi/2, etc.). you are providing fo...

6 years ago | 1

| accepted

Answered
i have a variable in my workspace and i dont know its name directly
Do not load directly into the workspace, always load into an output variable (which is a scalar structure): S = load(...); The...

6 years ago | 0

Answered
Extract number and infromation from multiple image files ?
One simple regular expression does this quite efficiently: D = 'Defolder'; S = dir(fullfile(D,'*.jpg')); N = {S.name}; T = r...

6 years ago | 1

Answered
Add lines (data) to a fopen file without overwriting the previous data
Try the append option: https://www.mathworks.com/help/matlab/ref/fopen.html#btrnibn-1-permission NS = fopen(... ,'a+'); % ...

6 years ago | 0

| accepted

Answered
How to find minimum value from loop using if function iteration?
>> a = 135500; >> dx = 1000; >> b = floor(a/dx) b = 135

6 years ago | 0

| accepted

Load more