Answered
Textscan Importing Multiple Inputs From One Text File
S = readlines('ResultA3forMatlabv2.txt'); F = @(s)sscanf(s,'%f,'); C = arrayfun(F,S,'uni',0) C{1:3} % the first few lines

5 years ago | 0

Answered
Print output if elements of a list match values in a column
A = [1;2;3;4;5;6;7;8;9;10]; B = ["A";"B";"C";"D";"E";"F";"G";"H";"I";"J"]; e = [3;6;8;10]; C = ["A";"A";"B";"F";"D";"H";"C";"...

5 years ago | 0

| accepted

Answered
Why this code gives error?
Exactly as the plot documentation shows, the LineSpec must come directly after the X/Y data: plot(f,20*log10(FFT_abs/max(FFT_ab...

5 years ago | 0

Answered
Save several results from recursive function
In my experience by far the easiest way to achieve this is to use a nested function, something like (pseudocode): function out ...

5 years ago | 1

| accepted

Answered
Why can't I put the 1x3 matrix into 1x3 variable?
"Why?" Because the square brackets have different meanings on the Left Hand Side (LHS) and Right Hand-Side (RHS) of the equals ...

5 years ago | 2

| accepted

Answered
How to use the parameters of other functions within the ‘cellfun’ function?
https://www.mathworks.com/help/matlab/math/parameterizing-functions.html f = @(a)smoothdata(a,'movemedian',100); x = cellfun(f...

5 years ago | 0

| accepted

Answered
I would like to compile a text string for each one of the three index of two given arrays
Simpler with compose: XX = [1,2,3,4.96875]; YY = [3,2,1,0]; fmt = "&DEVC ID=''vel_%g'', QUANTITY=''VELOCITY'', ABC=%d,0.0525,...

5 years ago | 0

| accepted

Answered
compare two vectors then insert missing element
Simpler: A=[ 1.000 0.5860 0.01403 2.500 0.7395 0.01277 3.500 0.8450 0.01146 4...

5 years ago | 0

Answered
Taking a string from a string array then identifying the characters within that string
A string array is a container class: it contains character vectors. Use curly braces to get the character vectors: w = ["aisle"...

5 years ago | 1

Answered
How can I use inputdlg() to store multiple variables and then use those variables in equations for later?
>> C = inputdlg(["m","b","k","x1","x2","F","w0"]) C = 7×1 cell array {'1.2'} {'2.3'} {'3.4'} {'4.5'} ...

5 years ago | 0

| accepted

Answered
Problem with vertically Concatenating vectors in a function
Rather than using a loop, a much better use of MATLAB would be to use comma-separated lists: https://www.mathworks.com/help/mat...

5 years ago | 0

| accepted

Answered
How to create table from struct array
Note that mixing up meta-data (the date) into fieldnames forces superfluous nesting of structures. This poor data design has alr...

5 years ago | 0

| accepted

Answered
Smallest positive number in MATLAB
eps(0) returns the smallest positive non-zero floating point number, which is denormal: format hex eps(0) Normal and denormal...

5 years ago | 2

| accepted

Answered
Understanding the structfun() or cellfun() commands
Avoiding CELLFUN or STRUCTFUN is simpler and much more efficient: S = dir('*_M.csv'); V = sscanf([S.name],'%f_M.csv')

5 years ago | 0

Answered
how can I store chars of a cells with different length in a matrix
C = cell(N,0); for k = 1:N tmp = ... the output of your function (cell vector) C(k,1:numel(tmp)) = tmp; end

5 years ago | 0

| accepted

Answered
How to run a matlab code for all folders in a directory?
"Is there a way to run tha matlab code for all the folders with automated manner? " Of course, just use DIR. For example: P = ...

5 years ago | 2

Answered
How to fscanf a text file of characters to a string array/vector, but not a 1x1 string?
str = readlines('sample.txt')

5 years ago | 1

| accepted

Answered
Problem with adding integers
..+(Vehicle9{index(9)})+... % ^ missing DOUBLE

5 years ago | 0

| accepted

Answered
read each line a text file using Matlab function
opt = {'Delimiter',{':',' '}}; fid = fopen('data.txt','rt'); nmc = nnz(fgetl(fid)==':'); frewind(fid); fmt = repmat('%s%f',1...

5 years ago | 1

| accepted

Answered
how to insert fprintf value into GUI edit text box?
You need to use sprintf, not fprintf: sprintf creates a character vector/string (this is what you need). fprintf prints direct...

5 years ago | 0

| accepted

Answered
Sorting the name field in dir command
You could download my FEX submission natsortfiles: >> S = dir('*.txt'); >> S.name ans = '1.txt' ans = '10.txt' an...

5 years ago | 1

Answered
How to concatenate horizontally a cell into another cell based on a vector
X = [1,1,2,2]; C = {rand(3,2),rand(3,1),rand(3,2),rand(3,1)}; C{:} Method one: arrayfun F = @(x)[C{x==X}]; D = arrayfun(F,1...

5 years ago | 1

| accepted

Answered
MAtrix Indexing with a vector that contains colon
The colons must be character, the numeric indices must be numeric (not char like you tried): A = rand(4,3,2,4,3,2,4,3,2,4,3,2);...

5 years ago | 0

| accepted

Answered
Extract string with regexp()
inp = {'$abc_in','def_in_hij_out[]','xyz'} out = regexprep(inp,{'_(in|out(\[\])?)?\>','\W+'},'')

5 years ago | 0

| accepted

Answered
Add an array to a cell arrayn within a for loop
V = [321,123,145,908,123,13,1,643,16,134,212,674,121,222,11]; X = [3,7,11,15]; F = @(b,e)V(b:e); C = arrayfun(F,X(1:end-1),...

5 years ago | 0

| accepted

Answered
My plot comes up as a white graph with no line.
The basic problem is that this syntax if t==1,2,3,4,5; is equivalent to writing this (i.e. each expression is evaluated indepe...

5 years ago | 0

| accepted

Answered
Conversion from string to numbers within table
Most likely you should fix the data importing, rather than messing around with converting strings. load('data.mat') T = varfun...

5 years ago | 0

Answered
Help with if statement in a calculation loop
The simplest and most efficient solution is to use MIN and MAX: x = 5 + randn(5,7)*1.5; x = x*1.3 + 0.5 x = min(max(x,1),10)...

5 years ago | 0

| accepted

Answered
When creating a vector why does the size change when using a variable vs using a value?
"How come the variable is exactly the same value but gives a different answer?" No, the values are not exactly the same. In on...

5 years ago | 0

| accepted

Answered
Why 'PreserveFormat' in writetable returns error?
The 'PreserveFormat' option was added in R2020b: https://www.mathworks.com/help/matlab/release-notes.html?rntext=PreserveFormat...

5 years ago | 0

| accepted

Load more