Answered
What is the best way to create a vector with a special sequence of subvectors
Store the vectors in one matrix, then you just need to use nchoosek to generate the required indices: >> M = randi(9,5,3) % eac...

7 years ago | 0

| accepted

Answered
Converting numbers into logicals
>> A = {[3;5;6;8],[2,3,5]}; % fake data >> B = cell2mat(cellfun(@(v)ismember(1:9,v),A(:),'UniformOutput',false)) B = 0 0 ...

7 years ago | 0

| accepted

Answered
Indexing a matrix with an array
Use a cell array, e.g.: C = {2,3}; % use NUM2CELL(I) if required. A(C{:}) Tested: >> A = rand(4,4) A = 0.340974 0.252...

7 years ago | 0

| accepted

Answered
Expanding the existing Matrix
Use repelem or kron, e.g. where V is your input vector: Z = repelem(V,24) or Z = kron(V,ones(24,1)) % adjust to suit V's orie...

7 years ago | 0

| accepted

Answered
How to concatenate a 3D cell array along the 3rd dimension?
In one line using num2cell, cellfun, and vertcat: >> C1 = cell(2,2,3); % preallocate cell array. >> C1(:) = cellfun(@(~)rand(1...

7 years ago | 0

| accepted

Answered
How to find the element of a number if that number were to be placed in an ordered list?
The robust solution: >> ida = find(list<number,1,'last') ida = 3 >> idb = find(list>number,1,'first') idb = 4

7 years ago | 2

| accepted

Answered
fprintf can't make new line
Try opening the file in text mode, not binary mode: A = 5; tcl = regexp(fileread('old_file.tcl'), '[\n\r]+', 'split')'; tcl{3...

7 years ago | 1

| accepted

Answered
Same number of Rows and Cols of a matrix (N*N)
This will return false for non-square matrices, and also if ndims>2: isequal(0,diff(size(M))) It is easy to use with assert: ...

7 years ago | 0

Answered
complex plots bug?
"Am I doing something wrong or is this a bug in Matlab plotting?" There is no bug in the plotting. Exactly as documented, when...

7 years ago | 0

| accepted

Answered
How to store " first_element " values?
No loop needed, here using accumarray: >> A = [1,1,1,1,2,3,4,4,4;1,2,3,4,5,5,5,5,5] A = 1 1 1 1 2 3 4 4 4 ...

7 years ago | 2

Answered
Converting a matrix of strings to a txt file
the format string need to have 3 conversion operators (or as many as you want on each line). the matrix needs to be tranposed. ...

7 years ago | 1

| accepted

Answered
How to find duplicated values and calculate the mean of them?
Here is one solution: >> M = dlmread('all_velocities.txt'); >> [~,~,X] = unique(M(:,1:2),'rows'); >> F = @(x) mean(M(x,:),1)...

7 years ago | 0

Answered
Extracting specific values from a Matrix
Use sub2ind: >> V = randi(1024,1,1280); % fake vector of row indices. >> M = rand(1024,1280); % fake matrix of data. >> S ...

7 years ago | 0

| accepted

Answered
Are these the same: set(0, ... and set(groot, ...
"Are these the same: set(0, ... and set(groot, ..." No, they are not the same. Not even close to being the same. Zero is a num...

7 years ago | 1

| accepted

Answered
Dealing with flags that are really comments
6. Give feedback to TMW that suitably rated users need the ability to change thread object types (without changing their other p...

7 years ago | 1

| accepted

Answered
Counting specific element in one column corresponding to unique elements in an another column
>> a = [1;1;1;1;1;2;2;2;2;2;3;3;4;4;4;5;5;5;5;5;5]; >> b = [1;1;-1;1;-1;-1;-1;-1;1;1;-1;1;1;-1;-1;1;1;-1;-1;1;1]; >> u = uniqu...

7 years ago | 0

Answered
How to use a data from time series (e.g.) in ode function?
You just need to get the numeric array out of the structure, e.g.: S = load('GasFlowRate_T.mat', 'Qg'); Qg = S.Qg;

7 years ago | 1

Answered
Error in unziping files loop
You need to include the path in the filenames otherwise MATKAB does not know where to find those files, e.g.: unzip(fullfile(di...

7 years ago | 0

| accepted

Answered
Cell array help with strings
>> x = {'Q';'N';'Q';'New';'Q';'N';'Q'}; >> y = 1+cumsum(strcmpi(x,'new')); >> z = strcmpi(x,'Q') | strcmpi(x,'L'); >> foo = @...

7 years ago | 1

Answered
Using loop to label multiple outputs
No need for a loop: >> X = [11;22;33;44]; >> fprintf('X%u = %u\n',[1:numel(X);X(:).']); X1 = 11 X2 = 22 X3 = 33 X4 = 44 I...

7 years ago | 0

| accepted

Answered
Match strings from 2 tables
Method one: outerjoin (TC rows may be in a different order to TA): >> TC = outerjoin(TA,TB,'MergeKeys',true) TC = Name ...

7 years ago | 1

| accepted

Answered
Error in unziping files and then deleting files in the zip
As its documentation clearly states, unzip's first input argument needs to be the name of a zip file. selpath is not the name o...

7 years ago | 0

| accepted

Answered
How to save multiple files in a 'for' loop
Move the coordinate=[] line inside the first loop: for t = 1:numel(i) coordinate = []; ... the rest of your code end...

7 years ago | 0

| accepted

Answered
How to pull a range of values out of an array using a loop
MATLAB is not Java. Using a loop would be entirely the wrong approach in MATLAB. >> idx = tau < 1e8; >> acceptable = tau(idx);...

7 years ago | 0

Answered
How to extract some rows from a matrix and put them in another matrix?
>> idx = ismember(Q,N,'rows'); >> Q(idx,:) = [] Q = 4 3 2 1

7 years ago | 0

| accepted

Answered
Trying to find the function of x for 0<=x<=2L
Two changes: you defined x to contain exactly one value, which is not very useful for plotting. you were missing some multipli...

7 years ago | 1

| accepted

Answered
Accepting multiple inputs in the form of an array
mnv = 1; mxv = 100; vec = []; while numel(vec)~=6 || any(vec<mnv | vec>mxv) || any(mod(vec,1)) str = input('Enter six in...

7 years ago | 0

Answered
Quick conversion of a large (and with mixed data types) cell array into a numerical array
This is likely to be faster than str2double. Use a decimal point rather than a decimal comma for more speed. >> C = {'1170790,8...

7 years ago | 1

| accepted

Answered
How can I count the number of 1 after every element of the vector?
>> X = [1,1,1,1,0,0,1,1,0,1,0,1,0,0,1,1] X = 1 1 1 1 0 0 1 1 0 1 0 1 0 0 1 1 >> Z = cumsum([...

7 years ago | 1

| accepted

Answered
Invalid expression in reading the file
function [rR,CL,effi1] = import_cl_effi(general_data,16, 45); % ^^ ^^ Not v...

7 years ago | 0

| accepted

Load more