Answered
error: Function definition is misplaced or improperly nested error?
"What could be the problem with it?" This: if ... ... function obj = bicomp1(c) Function definitions ca...

6 years ago | 0

| accepted

Answered
How do I generate 1000 random rows from an array only once, so that if I run the program again, it will still be the same set of randomly generated number previously
https://www.mathworks.com/help/matlab/math/generate-random-numbers-that-are-repeatable.html

6 years ago | 1

| accepted

Answered
Formatting .txt files as the one produced by command prompt.
Open the file in text mode: fileID = fopen('another_test.txt','wt'); % ^ you need this! and...

6 years ago | 1

| accepted

Answered
How to ignore letters in a numeric cell?
Simpler and much more efficient with sscanf: >> C = {'0.01mm';'0.02mm';'0.03mm';'0.04mm'}; >> V = sscanf([C{:}],'%fmm') V = ...

6 years ago | 1

Answered
check if values are in multiple ranges
>> a = [1,2,4,5,6]; >> val_bottom = [0,5,3,2]; >> vals_top = [5,10,8,12]; >> a(:)>=val_bottom & a(:)<=vals_top ans = 1 ...

6 years ago | 2

| accepted

Answered
Code failure on recent version of MATLAB
An empty permission string is not supported by the documentation: fopen(filename,''); % ^^ Not supported by the F...

6 years ago | 0

Answered
How do I remove redundant commas when writing a txt-file from a table?
Regular expressions make this easy (removes all trailing commas, removes the double quotes, and leaves the newlines unchanged): ...

6 years ago | 0

Answered
Assign variables while importing data
Do NOT use eval for importing data, unless you intentionally want to force yourself into writing slow, complex, buggy code. Read...

6 years ago | 1

| accepted

Answered
How to generate random number within a range?
>> 0.2+(1-0.2)*rand() ans = 0.85178

6 years ago | 0

| accepted

Answered
For loop for unequal increment
You are confusing two different ways of defining filenames. Currently you use dir to get the actual filenames from the OS, but t...

6 years ago | 0

Answered
How to split a string of digits into groups of three from right-to-left using only regular expressions?
With one regexp call (uses a lookaround assertion): >> str = '12345678'; >> regexp(str, '(^\d{1,2}(?=(\d{3})*$)|\d{3})','match...

6 years ago | 1

| accepted

Answered
Index 3D Array with 2D logical array
P = size(A,3); F = @(b,s)repmat(b,1,1,P)&reshape(ismember(1:P,s),1,1,P); % requires >=R2016b A(F(B,[1,2,3])) = A(F(B,[5,6,7]))...

6 years ago | 0

Answered
Finding three columns in one variable in another variable
I tried a simple vectorized solution of permute and sum of squares approach, but ran into "out of memory" issues: >> C = dlmrea...

6 years ago | 1

| accepted

Answered
How to extract numeric values from char
>> C = {'{"name":"rect","x":101,"y":30,"width":239,"height":244}'; '{"name":"rect","x":503,"y":88,"width":124,"height":165...

6 years ago | 1

| accepted

Answered
How to move values of matrix for 1 out of two rows?
>> M = [1,0,5,0;2,0,6,0;3,0,7,0;4,0,8,0] M = 1 0 5 0 2 0 6 0 3 0 7 0 4 0 8 0 >> M(2:2:...

6 years ago | 0

Answered
Creating RGB images with MATLAB
% 1. green at the left image border to black at the right border % 2. blue at the left image border to white at the right borde...

6 years ago | 2

| accepted

Answered
How can I fopen files in different directory
Do NOT follow advice of just adding more directories to the Search Path: this just pointlessly slows MATLAB down (MATLAB has to ...

6 years ago | 0

| accepted

Answered
How to use a vector to index another vector?
That function output is rather fragile, as there is no way to distinguish zeros (data) from zeros (place holders). This could ea...

6 years ago | 0

Answered
Shor Algorithm for prime factoring
You need to download bigmod from here: www.mathworks.com/matlabcentral/fileexchange/7908-big-modulo-function (the link is give...

6 years ago | 1

| accepted

Answered
find the nearest values
You were almost there, you just need to use the second output from min to make it easier: >> A = rand(1,2) A = 0.39011 0...

6 years ago | 2

| accepted

Answered
Selecting min value per row unless min value is repeated in another row.
Set the duplicate values to Inf/NaN, take the minimum of each row, then remove the Inf/NaN values: >> A = [1,2;1,3;2,3;5,6;3,7;...

6 years ago | 0

| accepted

Answered
Using a string shortcut for nested structure
For accessing a field of one specific structure (which can be nested) you should use dynamic fieldnames: https://www.mathworks....

6 years ago | 2

| accepted

Answered
How to save the result of stlwrite to a specific directory chosen by the user
TR = ... [F,P] = uiputfile('*.stl'); stlwrite(TR,fullfile(P,F))

6 years ago | 1

| accepted

Answered
While loop not starting
Lets have a look at the first y value: >> f = @(x) 4*x^2 - 3; >> x(1) = 0.5; >> y(1) = f(x(1)) y = -2 And now look at your ...

6 years ago | 1

| accepted

Answered
FSOLVE requires all values returned by functions to be of data type double
The function handle definition is incorrect: @(B)@ourfun What you defined is an anonymous function which when called accepts o...

6 years ago | 1

| accepted

Answered
Indexing with two matrices
>> [C,~] = find(bsxfun(@eq,permute(A,[1,3,2]),permute(B,[3,1,2]))); >> C = reshape(C,size(B)) C = 2 1 2 4 3 4

6 years ago | 0

Answered
Importing data with unequal number of column
This is very simple and efficient using fscanf: [fid,msg] = fopen('Data.txt','rt'); assert(fid>=3,msg) mat = fscanf(fid,'%f',...

6 years ago | 1

| accepted

Answered
Extracting second number after comma within parenthesis
Simply match all text from the comma to the whitespace: >> str = 'Toc(Clock Data Ref Time) : 0x91E6 (37350,5.976000e+005 s...

6 years ago | 0

Answered
Using strcmp with multiple inputs
You could use strfind or a regular expression to help you, e.g.: >> ixc = cellfun(@ischar,rw(:,3)); >> ixc(ixc) = ~cellfun('is...

6 years ago | 0

| accepted

Answered
declaring a new table
For historic and compatibility reasons if the variable does not exist before the dot-indexing allocates to it, then MATLAB will ...

6 years ago | 0

Load more