Answered
How to get only foldername with uigetdir
Use fileparts: fp = uigetdir('./subfolder1/'); [~,name] = fileparts(fp)

9 years ago | 1

| accepted

Answered
Open file in folder with numerical ID
You need to include the directory path when you open or read that file: usename = fullfile('C:File_path',fileList(1).name);...

9 years ago | 0

| accepted

Answered
How to effectively use look ahead with regexp?
1. _"searching the letter 'r' followed by a number."_ Actually you seem to be wanting to search for the letter |'r'| _preceded_ ...

9 years ago | 0

| accepted

Answered
How can I make the entries of a matrix be a square root of the sum of their column number squared and row number squared ?
*Method one: <https://www.mathworks.com/help/matlab/ref/ndgrid.html |ndgrid|>:* >> Rn = 4; >> Cn = 3; >> [Rv,Cv] = nd...

9 years ago | 0

| accepted

Answered
How can I generate random numbers in a range with decimal steps?
>> V = 0:0.1:0.5; % define the numbers >> V(randi([1,numel(V)])) ans = 0.4 >> V(randi([1,numel(V)])) ...

9 years ago | 4

| accepted

Answered
repelem substitute for older matlab version
>> A = [3,45,6]; >> R = [2,4,1]; >> cell2mat(arrayfun(@(a,r)repmat(a,1,r),A,R,'uni',0)) ans = 3 3 45 ...

9 years ago | 1

Answered
Reference struct field with an index and not it's name
You should use a <https://www.mathworks.com/help/matlab/matlab_prog/access-multiple-elements-of-a-nonscalar-struct-array.html no...

9 years ago | 0

| accepted

Answered
How to open a file if the user enters multiple parts of file name?
Try this: function myopen(varargin) D = 'test'; % the directory S = dir(fullfile(D,'*.txt')); N = {S(~[S.isdir]).n...

9 years ago | 1

| accepted

Answered
Why is it helpful to use regions/sections while writing a script in matlab?
Three good reasons: # Code folding: <https://www.mathworks.com/help/matlab/matlab_prog/improve-code-readability.html> # Run ...

9 years ago | 0

| accepted

Answered
I want to save variables to a mat file by reading variable names present in another mat file
This should get you started. 1. If the names are the _names of variables_ saved in the first mat file (e.g. |var1|, |var2|, e...

9 years ago | 1

Answered
How to replace non zero value with character
>> A = [0 0 1; 1 0 0;0 2 0]; >> C = repmat({''},size(A)); >> C(A~=0) = {'OK'} C = '' '' 'OK' 'OK' '' ...

9 years ago | 1

Answered
How to update an edit box window continuously by dragging a slider in Matlab GUI?
Here is a complete working solution for pre-R2014b MATLAB, that updates an edit box while dragging the slider: ht = uicontr...

9 years ago | 0

Answered
inputdlg string and convert variable to string
You should start by actually reading the documentation of the functions that you are using. If you had done this then you would ...

9 years ago | 1

| accepted

Answered
Segmenting a large data set into a subset then sequencing the subset
Some ideas for you to try: * |diff| and |cumsum|. * |unique|'s third output. * |accumarray|. * etc, etc But without any...

9 years ago | 0

| accepted

Answered
splitting matrix based on a value in one column
Hard-coded indexing: >> M = [7,0;10,0;16,0;19,1;26,1;29,1;3,1;5,0;69,0;36,0;78,0]; >> M(M(:,2)==0,:) ans = 7 ...

9 years ago | 10

| accepted

Answered
How to open a file if the user enters part of the file name?
This works for me: function myopen(str) S = dir(sprintf('*%s*.txt',str)); cellfun(@winopen,{S.name}); end and t...

9 years ago | 1

| accepted

Answered
Truncating vector to longest continuous string of numbers
>> m = [1,2,3,4,5,6,-5,-5,-5,1,2,3,4,5,6,7,-5,-5,-5,-5,1,2,3,4]; >> d = diff([false,diff(m)==1,false]); >> vb = find(d>0...

9 years ago | 1

Answered
Trouble finding text in cellarrays that are class "cell"
class(cellarray{1}) Note the curly braces. <https://www.mathworks.com/help/matlab/matlab_prog/access-data-in-a-cell-arra...

9 years ago | 1

| accepted

Answered
How do I average two arryas that have Nans?
>> nanmean([A;B],1) ans = 2 3 6 6

9 years ago | 0

| accepted

Answered
How do I extract a portion of a string after a prescribed symbol?
>> fileparts(mystring) ans = C\users\me\data

9 years ago | 0

| accepted

Answered
How to set regexp so that it stops to the first istance?
You could use a lazy quantifier |?| (explained in the <https://www.mathworks.com/help/matlab/matlab_prog/regular-expressions.htm...

9 years ago | 1

| accepted

Answered
how to create structure that persists over multiple runs of the same code
<https://www.mathworks.com/help/matlab/ref/persistent.html>

9 years ago | 0

| accepted

Answered
how to find difference between column elemnts in a matrix ?
A general solution (without hard-coded columns): >> M(:,1:2:end) - M(:,2:2:end) ans = 1 9 6 -1 0 ...

9 years ago | 1

| accepted

Answered
Line numbers when files are being saved in cell array
This simple code works on the cut-down files, you can try it on the full-size files and see what happens. I used dlmread to read...

9 years ago | 0

Answered
Generate comma separated list in single line of code?
_"I would like to put a piece of code within an expression which generates a comma separated list, without having to create a du...

9 years ago | 3

| accepted

Answered
Convert vector of datenum values to datetime values
It seems that |b| is a cell array, and each cell in the first column contains one scalar datenum. You can use |cell2mat| to conv...

9 years ago | 1

| accepted

Answered
issues with sort_nat and natsortfiles; error improper matrix reference
natsortfiles can now sort the DIR structure directly: >> S = dir('*.txt'); >> S.name ans = '1.txt' ans = '10.txt' ...

9 years ago | 1

| accepted

Answered
Index slice of ND array of unknown dimension
If you do not know the size of the array before hand then you can call <https://www.mathworks.com/help/matlab/ref/subsasgn.html ...

9 years ago | 4

| accepted

Answered
replication of elements in a vector
repelem(x,indx)

9 years ago | 0

| accepted

Load more