Answered
How to use a for cycle for opening .mat files
The general concept is shown here: https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html You ca...

5 years ago | 2

| accepted

Answered
list MATLAB functions with a script
Use this: https://www.mathworks.com/help/matlab/ref/matlab.codetools.requiredfilesandproducts.html possibly with the '-toponly...

5 years ago | 0

Answered
Convert character vector to evaluable expression
S.field1.subfield = 5; % do NOT use STRUCT as a variable name. vec = 'S.field1.subfield'; spl = split(vec,'.'); val = getfiel...

5 years ago | 0

| accepted

Answered
Extracting data from text file
Method one: TEXTSCAN: fmt = '%s%f%f%f'; opt = {'MultipleDelimsAsOne',true, 'CollectOutput',true, 'HeaderLines',1}; fid = fope...

5 years ago | 0

| accepted

Answered
Extracting Time Data from Text File
Simpler and more efficient: str = fileread('test_1.txt'); tkn = regexp(str,'^\s*(\d+):\D+(\d+\.?\d*)\W+([^\n\r]+)', 'tokens', ...

5 years ago | 1

| accepted

Answered
How to extract the result after each iteration while using for loop?
With MATLAB it is almost always better to loop over indices rather than over data values. That makes it easier to save the data ...

5 years ago | 1

| accepted

Answered
How can you write a matlab code from the 2018 version back to the 2013b version?
"How can you write a matlab code from the 2018 version back to the 2013b version" By very carefully reading the documentation f...

5 years ago | 0

Answered
Save data from subfolders into a cell array
P = 'absolute or relative path to where the subfolders are'; N = 'the name of the file that you want.CSV'; S = dir(fullfile(P,...

5 years ago | 0

| accepted

Answered
How to arrange a column vector into two columns?
Assuming that the missing 236/237 row is a mistake: x = [128,147,166,181,195,216,236,255] m = [x(1),1+x(2:end-1);x(2:end)].'

5 years ago | 0

| accepted

Answered
I want to write a loot to open multiple files with fopen and stack it with fscan but my code does not work. Any suggestions?
P = 'absolute or relative path to where the files are saved'; S = dir(fullfile(P,'*.txt')); for k = 1:numel(S) F = fullfi...

5 years ago | 0

Answered
Did I do anything wrong when I used the "second" function?
"Did I do anything wrong when I used the "second" function?" Yes, you supplied the wrong input class: as its documentation clea...

5 years ago | 0

| accepted

Answered
Extracting values from array separated by zeros
V = [0,0,0,0,0,2,3,4,5,0,0,0,0,0,1,1,2,3,0,0,0,0,0,0,4,5,1,2,0,0,0,0]; D = diff([true,V==0,true]); B = find(D<0); E = find(D>...

5 years ago | 0

Answered
1D interpolation over vector of observations with linear extrapolation
The query points do not have to be scalar: interp1(grid, func, obs ,'linear','extrap')

5 years ago | 0

Answered
How to keep rows whose values follow a certain sequence?
Here is an old MATLAB trick that you can use, which still works today: https://blogs.mathworks.com/loren/2008/09/08/finding-pat...

5 years ago | 0

| accepted

Answered
Shortening if/elseif loop for value segregation
What you are doing can be broken into two parts: the first part is generally known as data binning. You can do data binning quit...

5 years ago | 1

| accepted

Answered
How do I multiply digits of a given number?
N = 12345; S = num2str(N); prod(S([1,3])-'0')

5 years ago | 0

Answered
my problem is about @.
f = @(x) x.^2; % ^ ^ you forgot these parentheses q = quad(f,1,2) How to define anonymous functions is explained here: ht...

5 years ago | 1

| accepted

Answered
How to automate .mat file loading
You can use the approaches shown in the documentation: https://www.mathworks.com/help/matlab/import_export/process-a-sequence-o...

5 years ago | 0

| accepted

Answered
Sorting and Re-arranging a text file using Matlab by a specific column
T = readtable('test.txt') T = sortrows(T,'ID') G = findgroups(T.ID); S = groupsummary(T,"ID",{"max","sum"},"Number"); S = re...

5 years ago | 0

Answered
I'm trying to convert date numbers to character dates, I created a vector using datenum and manually entering each date in Y,M,D,H,M,S format, and it works but I hope to find
As Steven Lord and Walter Roberson and the MATLAB documentation recommended, you should use DATETIME objects, which can be plott...

5 years ago | 0

Answered
How to select specific files from all the files in a folder?
This is easy using COPYFILE or MOVEFILE with the appropriate wildcard characters, e.g.: P = 'absolute or relative path to where...

5 years ago | 0

| accepted

Answered
Get the position of the max and min values of a variables
[b,index] = maxk(lat1,5); % ^^^^^ the second output is the index

5 years ago | 0

| accepted

Answered
Program to count the number of letters in a character sentence seems to not count the 58th character.
if char(i)==texte(char(j)) % ^^^^^ ^ get rid of this The code could be simplified using HISTCOUNTS, LOWER, etc...

5 years ago | 0

| accepted

Answered
How read the exact number of decimal digits with readtable from a .csv file?
This imports the data as text, converts to numeric for the filter calculation, and then saves the text. Caveat: it does not pres...

5 years ago | 1

| accepted

Answered
From separate channels to RGB
I am guessing that the image files are actually Truecolor RGB (with all channels identical) rather than true Grayscale (a sadly ...

5 years ago | 0

| accepted

Answered
How change unit8 pixel value to intensity data
https://www.mathworks.com/help/matlab/ref/im2gray.html

5 years ago | 1

Answered
Write a Matlab code to check. .. whether a given number is an amstrong number using functions.
N = 153; S = num2str(N); Z = N==sum((S-'0').^numel(S))

5 years ago | 0

Answered
Load data with varying names
The MATLAB documentation explains how: https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html Th...

5 years ago | 1

| accepted

Answered
NEED TO READ A FILE AND STORE VALUES
I shortened the file a bit by removing some lines from the middle of those data blocks. opt = {'Delimiter','\t', 'CollectOutput...

5 years ago | 1

| accepted

Answered
Sort Matlab table based on pre-defined order
You could do something like this, where C is that column: D = {'B';'A';'C';'D'}; % the desired order C = {'C';'C';'A';'D';'B';...

5 years ago | 0

| accepted

Load more