Answered
What is the best way to implement thousands of data in multiple matrices ?
I would not use either of the first two methods, because they are an easy way to get latent, almost undetectable errors in your ...

6 years ago | 0

| accepted

Answered
Replacing Values Between a 0 and a 1 in a Vector
This should be reasonably efficient: A = [0,0,0,2,2,2,1,2,1,2,2,0,0]; D = diff(A); B = find([0,D]==2); E = find([D==-1,true]...

6 years ago | 0

Answered
Toeplitz Matrix Generation from 2 MATRICES
>> A = rand(3,3); >> B = rand(3,5); >> N = 4; >> F = @(n)(A^n)*B; >> C = arrayfun(F,0:N,'uni',0); >> C = [{zeros(size(B))},...

6 years ago | 0

| accepted

Answered
Reading data from ASCII file
Importing the entire file data as character, converting to string, spltting that string into multiple little strings, and then f...

6 years ago | 0

| accepted

Answered
if all elemets of a array equal, which array will be choose by MAX function?
There is no inbuilt function, but you can do it yourself very easily: >> a = [0,0,0,0,0]; >> ida = find(a==max(a)); >> idx = ...

6 years ago | 0

| accepted

Answered
How to set the no if iterations of a for loop dynamically ?
The MATLAB approach is to do these two steps before the loop: create a cell array of the folder names use setdiff or ismember ...

6 years ago | 0

| accepted

Answered
How to save fields of a struct through for loop iteration.
You don't need a loop, just use the -struct flag to save the fields of a scalar structure: save(filename,'-struct','data') Whe...

6 years ago | 0

| accepted

Answered
Declaring types in MATLAB
"When preallocating, is it possible to declare types? " When preallocating you can select any suitable data type, e.g.: A = ze...

6 years ago | 0

| accepted

Answered
Multiple outputs by a loop
Replace the fopen with these two lines: fnm = sprintf('output%d.txt',i); fid = fopen(fnm,'wt');

6 years ago | 0

Answered
how can i plot the function of each function?
"what's wrong on this code?" if does not change subsets of an array like that (you would need to use if inside of a loop). You...

6 years ago | 0

| accepted

Answered
Skill with regexprep?
This should get you started: >> str = '5*0.02 0.02 0.04 0.08 0.15 0.3 0.5 1 2 3 30*5 30*10 30*20 30*40 30*60'; >> fun = @(n,c)...

6 years ago | 0

| accepted

Answered
Creating a structure from a cell array with nested structure fields
Nope, that won't work. Best approach: split on the period characters, then use setfield and getfield as appropriate: S.field1....

6 years ago | 0

| accepted

Answered
(1/3)*3-1 evaluates to 0 instead of some numerical error. Why?
The reason is very simple: because 1 is the closest (double) binary floating point number that can approximate the value of (1/3...

6 years ago | 2

| accepted

Answered
PLEASE HELP ME -- unexpected expression
fprintf('1. kök: %g \n 2. kök: %g \n ',y1,y2); % ^ your code is missing this comma % ...

6 years ago | 0

| accepted

Answered
Change of color of variables
The teal color indicates a shared scope for that variable: https://www.mathworks.com/help/matlab/matlab_prog/check-variable-sco...

6 years ago | 0

| accepted

Answered
List all cells that match logical criteria
>> C = {1,'13_dogs';[],'24_dogs';1,'100_dogs';[],'7_dogs'}; >> X = cellfun(@(a)isequal(a,1),C(:,1)); >> D = C(X,2); Checking:...

6 years ago | 0

| accepted

Answered
Randperm without number 1
r = 1+randperm(N-1,N20);

6 years ago | 0

| accepted

Answered
How can I save the outputted string (retaining tabs/added lines) to a .txt file?
[fid,msg] = fopen('yourfile.txt','wt'); assert(fid>=3,msg) fprintf(fid,'%s',MESSAGE); fclose(fid);

6 years ago | 0

| accepted

Answered
Randperm without the number 1
1+randperm(50-1)

6 years ago | 0

| accepted

Answered
MATLAB Faulty Logical Indexing?
"I suspect it is a potential bug" Nope. The cause is that you are testing for exact equality of binary floating point numbers. ...

6 years ago | 1

| accepted

Answered
Delete multiple elements from matrix, that match value at once
The simple MATLAB solution is to use ismember to generate the indices: >> A = [1,2,3,4,5;3,4,6,7,8;1,2,4,5,6;8,7,6,3,4;1,2,3,4,...

6 years ago | 0

| accepted

Answered
How to specify which version of a function to use?
The grpdelay documentation states "Frequencies, specified as a vector. fin must have at least two elements, because otherwise th...

6 years ago | 0

| accepted

Answered
Matlab Sort Command Output
Using separate variables makes this rather complex. It would be much simpler if you stored the data in arrays, e.g. in one tabl...

6 years ago | 1

Answered
How to extract data from cell array
Because you did not upload a sample file I created one (attached) based on your example data. str = fileread('trial.txt'); % re...

6 years ago | 0

| accepted

Answered
Automatic import of data and rename of array
Creating lots of dynamically named varaibles is not a good approach, and should be avoided. You should follow the examples in t...

6 years ago | 0

| accepted

Answered
Generating linear array [0 -1 0 1 -2 -1 0 1 2 ......]
N = 4; C = cell(1,N); for k = 1:N C{k} = -k:k; end V = [0,C{:}] Giving: V = 0 -1 0 1 -2 -1 0 1 2 -3...

6 years ago | 3

| accepted

Answered
How to find the indeces of same values within two vectors with repetitive values?
The example data from your question: >> A = [1000,2000,2000,5000,20000,20000]; >> B = [1000,2000,2000,5000,10000,20000,20000,6...

6 years ago | 1

| accepted

Answered
How to search for strings in strings?
>> str = '011_c_srr_Rtzfi_at000_hh5_fs_v343_l067_i1_Test_Test'; >> tmp = regexp(str,'(?<=_l)\d+','match','once'); >> num = str...

6 years ago | 0

Answered
What am i doing wrong? This expression is violating basic Mathematics.
Your code has two loops, loop j is nested inside loop i. You allocate data to pos1 only using index j, which means that you rep...

6 years ago | 0

| accepted

Answered
Splitting vectors into cell array in a loop
>> a = [1,3,5,7,9,10,8,6,4,3,2,3,5,6,9,10,7,5,3,2,1,3,4,6,8,9,10]; >> d = [false,diff(a)>0,false]; >> B = find(diff(d)>0); >>...

6 years ago | 0

| accepted

Load more