Answered
how can sort the numbers according to the numbners in the first column
A general solution using accumarray: >> x = [1,2;1,3;1,2;2,4;2,6;1,7;3,8;3,9] x = 1 2 1 3 1 2 2 4 ...

7 years ago | 0

| accepted

Answered
How do I import a file containing both numbers and strings
Use textscan and set its 'TreatAsEmpty' option to 'X'. This will be much more efficient than importing and post-processing (e.g...

7 years ago | 2

| accepted

Answered
execute a script in a loop
"The script executes the inputs and gives me outputs, the outputs are crossponding to the input i.e output1, output2, output3, e...

7 years ago | 0

| accepted

Answered
check if elements in an array are equal to 0 1 or 2
"how do i check that all the elements witihin my array are equal to 0,1 or 2? " >> A = randi([0,2],4) % should pass A = 1 ...

7 years ago | 0

| accepted

Answered
Convert a string into a function of x
You can use str2func: fun = str2func(['@(x)',Sstr]); and then call it just like any other function.

7 years ago | 2

| accepted

Answered
How can I create a function which takes a matrix of characters as the input and outputs the number of specific characters within that matrix?
Two methods to count the exact sequence 'gc' on each line of the character matrix. Method one: convert to cell array, use strfi...

8 years ago | 0

Answered
Setting multiple variables to empty vectors
[flowm,flowmax,flowmin]= deal(zeros(12,1))

8 years ago | 0

| accepted

Answered
How can I create a for loop to count the number of letters in my array?
The simple MATLAB solution: >> V = 'ttgcgcatgcgcaca'; >> nnz(V=='g') ans = 4 Or to count occurances of all of the different...

8 years ago | 0

Answered
extracting row and column from a cell which contains numbers and strings
You don't need to use find, just get the second output from min: errorvals = cell2mat(mymatrix(:,11)) [minoferrorvals,idx] = ...

8 years ago | 0

Answered
datestr problem with month
If T.Date really is a datetime array, then use string to convert it to a string array. Make sure that you have set the datetime'...

8 years ago | 0

| accepted

Answered
Find number of vowels
The simpler MATLAB way: >> vc = @(s) nnz(ismember(lower(s),'aeiou')); >> vc('hello world!') ans = 3

8 years ago | 1

Answered
How i can use function handle in another function handle?
"How i can use function handle in another function handle?" Exactly like any other time you use a function, you have to call it...

8 years ago | 0

Answered
how I do it. the function is called a string is passes a numbr
function out = myfun(inp) persistent cnt if nargin==0 || isempty(cnt) cnt = 0; end cnt = cnt+1; assert(cnt<=5,'You alread...

8 years ago | 0

| accepted

Answered
How to import the image with the number.
Luckily those dates use an ISO 8601 date format, so you can simply import them sorted into character order: S = dir('*.tif') F...

8 years ago | 0

| accepted

Answered
Reference to non-existent field 'xd'. Kindly help .
The problem is related to structure C, not structure S. The fields xd and yd of structure C are defined inside while loops whos...

8 years ago | 1

| accepted

Answered
Correct indexing in a for loop - my array fills gradually?
"What am I doing wrong?" You are using a logical array as an if condition... unfortunately this is allowed, but makes no sense ...

8 years ago | 0

Answered
How to go through multiple subfolders for operation?
"For better explaining if i have one folder named 'JSR' which contains subfolders name '1', '2', '3', '4'...................

8 years ago | 0

| accepted

Answered
hi, im tring to make a new vector from some exics one.
The MATLAB way: >> grades = [87,81,87,80,94,87,62]; >> sch = grades(grades>85) sch = 87 87 94 87

8 years ago | 0

Answered
Please Assist with plotting graph from multiple files, so far the code only reads one file a multiple times.
D = 'C:\Users\NSebopetse\Pictures\nakampe-optiplex-760'; S = dir(fullfile(D,'san_2018*')); % better to include the file extensi...

8 years ago | 0

| accepted

Answered
How to group dynamically different fields from a structure ?
This is a very good example of why putting meta-data into variable names or fieldnames makes code pointlessly complex. If that d...

8 years ago | 1

| accepted

Answered
i have more than 100 mat files with data inside them. how to extract all the data inside the matlab file to the matlab workspace so that i can plot a graph with it ? Help me..
https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.html Simply load each mat file into a variable,...

8 years ago | 0

| accepted

Answered
How to select a folder using uigetdir and use folder location later?
Do NOT use strcat, you should always use fullfile to build filepaths, just like you did for dir. Like this: aa = fullfile(direc...

8 years ago | 1

| accepted

Answered
how can an function containing structure data can be used in main code while main code also containing same/different structure.
function c = practice2; str2.d = randi([0,10],1,8); c = str2.d; end and then: str1.a=randi([0,10],1,8); str1.b=randi([-1...

8 years ago | 0

| accepted

Answered
Unexpected fault in input
You did not enter any value, so FF is empty. Any empty array cannot be expanded to fill the non-empty locations that you have s...

8 years ago | 1

Answered
What is wrong with the indexing
MATLAB does not allow parentheses to trail other parentheses, so this is now allowed: diff(y,t)(0) You will have to use a temp...

8 years ago | 0

Answered
how to remove some lines of a file?
I suspect that you want something like this: beg = '*Elset, elset=granulation'; % first line to remove. num = 4; % lines to re...

8 years ago | 0

Answered
How to randomize a specific number of 0s and 1s so that 0s always precede at least two 1s?
>> n0 = 70; >> n1 = 170; >> v = char('0'+[zeros(1,n0),ones(1,n1-2*n0)]); >> v = strrep(v(randperm(numel(v))),'0','110')-'0'; ...

8 years ago | 1

Answered
Regexp formatting and explanation
>> S = '0051-21194_3 Rev 09_P02109461-011_8-1-18'; >> R = '^(\d+-\d+)[^R]{0,4}(Rev\s\d+)\w+-\d+_(\d+-\d+-\d+)$'; >> T = regexp...

8 years ago | 1

Answered
How to parse variables independent of order
It would help most if you uploaded a sample file, so we have something to work with. But here is a simple working example of how...

8 years ago | 2

| accepted

Load more