Answered
Can't seem to replace values in matrix meeting criteria, although the correct row,col coordinates are found
Use SUB2IND: idx = sub2ind(size(img),row,col); img(idx) = 1; The section "Indexing Matrices with Two Subscripts" here: https...

1 month ago | 0

| accepted

Answered
Compare two files and remove any lines in the second file when they match values found in the first file
lines1 = [1,2,3,4;2,4,6,7;2,5,7,8;6,7,4,6] lines2 = [2,4,6,7;2,5,7,8] out = setdiff(lines1,lines2,'rows')

1 month ago | 0

| accepted

Answered
A more efficient or compact way to sort strings that contain dates
a = [... '123_abc_01_202403020000_202403022359.txt'; '123_abc_01_202403040000_202403042359.txt'; '123_abc_01_2024...

1 month ago | 1

| accepted

Answered
Portion of code containing my custom functions is hidden and I cant access it.
The feature is called code folding: https://www.mathworks.com/help/matlab/matlab_prog/edit-and-format-code.html#brazeg3-1 http...

1 month ago | 1

Answered
How can I access the value of a string variable? I need to construct a file path from a string variable, but keep getting the variable name and not the string.
It works perfectly, exactly as you showed in your question: directory_name = "directory1"; f = fullfile('/Users/me/ch4', direc...

1 month ago | 1

Answered
Appending data when extracting nested fields as individual variables
The simple and efficient MATLAB approach using two comma-separated lists (no loops are required!): first100 = load('frames.mat'...

1 month ago | 0

| accepted

Answered
char array to numeric array
"I was wondering if there was a better way of doing this?" Of course, use READTABLE (or READMATRIX): unzip tab_file_table.zip ...

2 months ago | 0

| accepted

Answered
I'm trying to convert the text into binary and then i want to make the 4 bits chunks.
message = 'Hello world'; A = dec2bin(message, 8) B = reshape(A.',1,[])

2 months ago | 0

Answered
How to stop double printing text using sprintf ?
Problems: 1- This is the relevant code: VariantModel = compose('%d', 1:height(VariantIDPassed)); .. writefile(VariantModel{i...

2 months ago | 0

| accepted

Answered
How do I fix my Nan issue within a recursive function?
Replace this (which returns logical indices): FirstID = M==-1; with this (which returns the linear index): FirstID = find(M==...

2 months ago | 0

Answered
How to import multiple .mat files to workspace?
The basic problem is that you are not supplying the filepath to LOAD. You can improve your code as well. I am guessing that you...

2 months ago | 0

| accepted

Answered
Error in code, parenthesis perceiving as comment for some reason
Explanation: for some reason you seem to be running this literal code: Q_est = updateQ(...) instead of calling UPDATEQ etc. wi...

2 months ago | 1

Answered
smart function to switch functions
You could use STR2FUNC: str = 'ode23'; odesolver = str2func(str); odesolver(@fun,..) or simply use FEVAL: feval(str,@fun,.....

2 months ago | 0

| accepted

Answered
Reshaping a matrix based on the first row
A = [270,270,270,271,272,272,273,273,273]; B = [ 12, 2, 3, 14, 5, 2, 6, 8, 11]; X = ~isnan(A); C = findgroups(A(X)); R...

2 months ago | 0

Answered
sorting non-exact x/y data into rows and columns, typewriter style
x = [1.01,2.01,1.02,2.02]; y = [1.01,1.02,2.01,2.02]; m = [x(:),y(:)]; % simpler [~,id] = sortrows(round(m),[-2,+1])

2 months ago | 0

| accepted

Answered
How can I extract an array of numbers from a text-formatted cell array of strings.
C = {'20s';'15m';'';'24s';'';'44s';'3h';'40m';'20s';'';'14s'} F = @(t)prod(sscanf(t,'%f')); V = cellfun(F,regexprep(C,{'h$','m...

2 months ago | 1

| accepted

Answered
Update an Excel file after each Matlab calculation
You can use a COM server to trigger Excel to recalculate the worksheets: https://www.mathworks.com/matlabcentral/answers/100938...

2 months ago | 0

Answered
Error using (function_name). Too many output arguments.
You did not define the function to return any output arguments: function calcolo_cp(T,fluido) If you intended to return e.g. C...

2 months ago | 2

Answered
Vectorize nested for loops with indices and subscripts
A = [1,2,0,2;2,1,3,0;0,3,1,3;2,0,3,1] matArray = unifrnd(-1,1,[4,4,10]) Method one: [X,Y] = meshgrid(1:size(matArray,3),A(:))...

2 months ago | 0

| accepted

Answered
Can a custom argument validation function alter the field names of its input variable?
The hard part is not validation, but mapping random fieldnames to your desired fieldnames. Notet that argument validation does ...

2 months ago | 0

| accepted

Answered
How to write all cells of structure in excel sheet ?
Why is a scalar structure nested inside a (pointless) scalar cell array? Why are lots of scalar numerics stored inside a cell a...

2 months ago | 2

| accepted

Answered
How to define variable names for resampling?
You should: replace the ISMEMBER with ENDSWITH get rid of those asterisks For example: endsWith(files(i+j).name, {'_B03_10m....

2 months ago | 0

| accepted

Answered
How should I fix my regular expression to parse this txt file?
"It seems that my regular expression is way too broad and causing this problem." There are several locations where your regular...

2 months ago | 0

| accepted

Answered
What is the equivalent datetime() call to the clock() function?
Note that DATETIME is an object with properties, so (depending on your requirements) accessing its properties is a simple option...

2 months ago | 0

| accepted

Answered
How can I convert matrix to cell?
https://www.mathworks.com/help/matlab/ref/mat2cell.html A = reshape(1:40000,100,400)'; C = mat2cell(A,4*ones(1,100),100)

2 months ago | 0

| accepted

Answered
How to name and save the results using the name of imported file ?
A much better approach is to store the data in e.g. a structure array: P = 'absolute or relative path to where the files are sa...

2 months ago | 0

Answered
Question on creating dynamic matrix variables
"Or alternatively, is there a neat way to do so?" Of course there is: indexing. Either into a numeric array or into a container...

2 months ago | 0

| accepted

Answered
Building an array of strings that might be empty
"What am I missing?" The differences between strings and characters. Do not mix up string arrays with character vectors (which ...

2 months ago | 0

Answered
Find a value using an index obtained from a different matrix with same dimensions
The efficient MATLAB approach: tmc = readmatrix('Total_matrix_cases.txt'); tmr = readmatrix('Total_matrix_rotation.txt'); [tm...

2 months ago | 0

Answered
Using a menu to generate variables for larger code
For the 1st dialog box: V = str2double(answer); maxvel = V(1); dragco = V(2); width = V(3); mass = V(4); accdur = V(5);...

2 months ago | 0

| accepted

Load more