Answered
textscan error only in loop: "Invalid file identifier. Use fopen to generate a valid file identifier"
This will not work as you require: fname=[pname, fname]; Instead you should use FULLFILE, to correctly handle the file separat...

4 years ago | 0

| accepted

Answered
Conversion of string containing "AM" or "PM" to datetime
str = "4/21/2022 8:48:40 AM"; dtm = datetime(str, "InputFormat", "M/d/u h:m:s a")

4 years ago | 1

| accepted

Answered
I am getting the error "Variable y must be of data type char. It is currently of type double."
extractemail('My email address is: raymond.kim@usc.edu so please email me') extractemail('There is no email here') function ...

4 years ago | 0

Answered
Store values from a matrix in a new size matrix
Assuming that you intend to print the matrix into a file (as your example shows): inp = randi(9,340,340); fmt = [repmat(' %15....

4 years ago | 0

| accepted

Answered
Function Named with String Substitution
"Is there a way in MatLab to use string substitution in the name creation of each function? " Yes, but only if you want to forc...

4 years ago | 0

| accepted

Answered
Split an Array in sub-arrays based on the first number in the column
M = [[0;0.2;0.2;0.4;0.6;0.6;0.6],rand(7,3)] D = diff(find([1;diff(M(:,1));1])); C = mat2cell(M,D,4) C{:}

4 years ago | 1

| accepted

Answered
Indexing inside variables name
for k = 1:N v1 = sprintf('Data%u_Asc',k); v2 = sprintf('Data%u_BML',k); fn = sprintf('File%u.mat',k); save(f...

4 years ago | 1

| accepted

Answered
Arrayfun with multiple variable?
"But if I have a function that requires more than one input how can I do?" ARRAYFUN already works with any number of input arra...

4 years ago | 0

Answered
Output cell values and column number for matrix with specific values
Without changing the input matrix A: A = [1,128,1,0,0,0,0,0,0,0,0,0,0;1,129,0,1,1,1,0,1,1,0,0,0,1;1,130,1,0,1,0,0,0,0,1,0,0,0;1...

4 years ago | 0

Answered
How to reshape matrix by column number?
D = [1,78,0,0,0,0,0,0,0,0,8,45,0;1,79,0,0,0,0,31,8,0,0,0,0,0;1,80,456,0,4,0,39,0,0,0,16,0,0] M = D(:,3:end).'; [C,R] = find(M)...

4 years ago | 1

Answered
Comparing Strings and Finding Differencies
Your current approach and other simple code based on STRCMP or comparing entire character vectors is not robust to insertions, d...

4 years ago | 1

Answered
Convert cell array containing hex and scientific notation into hex
Method one: CELLFUN: C = {'4a3';'8.00E+1';'3f00';'503'} X = contains(C,["+","-"]); F = @(s)sprintf('%x',sscanf(s,'%f')); C(X...

4 years ago | 0

| accepted

Answered
Concatenate fields of a structure
Note that using a string array is much more efficient than storing scalar strings in a cell array. app.C1.DHO = {{"ID1","GD1","...

4 years ago | 0

| accepted

Answered
How to read and separate specific parts (letters and numbers) in the same rows of a text file
fnm = 'brdc0250.txt'; opt = detectImportOptions(fnm,'FileType','fixedwidth', 'ExpectedNumVariables',11, 'VariableNamingRule','p...

4 years ago | 1

| accepted

Answered
how to save workspace variables with the same name they have in work space
A much simpler approach ist use SAVE's regular expression syntax: save('mydata.mat', '-regexp','^PSD') See the examples here: ...

4 years ago | 1

Answered
I want to include a variable in my figure title when I save to a directory.
TIMEend = 2029; fnm = sprintf('Final E monoton %u.fig',TIMEend); fpt = fullfile('.','PRCC plots for submission 2',fnm); savea...

4 years ago | 0

| accepted

Answered
How to programmatically modify substructure with arbitrary number of levels?
I would not write a function for this, just use SETFIELD with a comma-separated list: S.a.b = 1; C = {'a','b'}; N = 2; S = s...

4 years ago | 0

| accepted

Answered
Finding when spline interpolated data is equal to a number
X = [1,2,3]; Y = [1,2,4]; Yq = 3; pp = spline(X,Y); fh = @(xq)ppval(pp,xq)-Yq; Xq = fzero(fh,[1,4]) plot(X,Y,'+',Xq,Yq,'*'...

4 years ago | 0

| accepted

Answered
How to re-order a string array?
P = pwd; S = dir(fullfile(P,'*.txt')); C = {S.name}; [~,X] = sort(str2double(regexp(C,'\d+','match','once'))); C = C(X);

4 years ago | 0

| accepted

Answered
How I can extract data from a vector based on index
A simple and efficient approach: A = [5,3,7,8,89,6]; index = [2,3,4,5]; B = A; B(index) = []

4 years ago | 1

Answered
Concatenation of multiple matfile into one matfile
Assuming that each .mat file contains only one variable of unknown name: P = 'absolute or relative path to where the files are ...

4 years ago | 0

| accepted

Answered
Importing code from octave to matlab
tmp = abs(fft(c)); z = tmp(1:T*fs/2)/(T*fs);

4 years ago | 1

| accepted

Answered
How to repeat a prompt until a expected number is written by the user
A = 0; while ~ismember(A,1:4) A = input(..); end

4 years ago | 0

| accepted

Answered
Using readtable() for Excel file where only one column has mixed numbers and text
Of course you can specify the class, the simplest approach is probably via DETECTIMPORTOPTIONS and SETVARTYPE: fnm = 'filename....

4 years ago | 0

| accepted

Answered
How can I round a number to the higher whole number?
ceil(1.234) ceil(3.534)

4 years ago | 1

| accepted

Answered
Use strcmp() based on part of the row name in structure
Use https://www.mathworks.com/help/matlab/ref/endswith.html

4 years ago | 0

| accepted

Answered
How do I convert a vector into an Nx1 cell array of varying-length vectors?
Simpler: V = [1,2,3,4,5,6,7,8,9,10]; N = 3; L = numel(V); S = N*ones(1,ceil(L/N)); S(end) = 1+rem(L-1,N); C = mat2cell(V...

4 years ago | 0

Answered
Cell arrays into excel
Where C is your cell array: F = 'myfile.xlsx'; for k = 1:size(C,2) T = C{1,k}; M = C{2,k}; writematrix(M, F, 'S...

4 years ago | 1

| accepted

Answered
Line number in code
mytest() function mytest() % A = 1; B = 2; % F = @(s)s(1); % helper function % fprintf('%3u %s\n',F(dbstack()).line, 'he...

4 years ago | 0

| accepted

Answered
Remove equal sign and quotation marks in readtable
This should get you started. Note that you can tailor the range, etc. fnm = 'iv1_gdp_cum.csv'; opt = {'Delimiter',{',','='}, '...

4 years ago | 1

| accepted

Load more