6,047 total contributions since 2014

Suspensa Vix Via Fit

Answered

importing excel file to matlab without losing date format?

Simpler: >> T = readtable('test.xlsx','ReadVariableNames',false); >> T.Properties.VariableNames = {'ymd','HMS','data'}; >> D ...

importing excel file to matlab without losing date format?

Simpler: >> T = readtable('test.xlsx','ReadVariableNames',false); >> T.Properties.VariableNames = {'ymd','HMS','data'}; >> D ...

5 hours ago | 0

Answered

How do I get the date out of a filename using regexp?

In one line without intermediate indices or double vector: >> str = 'xxx_2014_06_03_00_00_01'; >> dtm = datetime(regexp(str,'(...

How do I get the date out of a filename using regexp?

In one line without intermediate indices or double vector: >> str = 'xxx_2014_06_03_00_00_01'; >> dtm = datetime(regexp(str,'(...

5 hours ago | 0

Answered

count string in a cell array

>> S = '945'; >> C = {'1234', '9456', '9457'}; >> nnz(~cellfun(@isempty,strfind(C,S))) ans = 2

count string in a cell array

>> S = '945'; >> C = {'1234', '9456', '9457'}; >> nnz(~cellfun(@isempty,strfind(C,S))) ans = 2

8 hours ago | 0

Answered

How do I call a function handle with an vector - rather than a list of arguments

Easy: first define a cell array: C = {a1Init, wG1, x1,a2, wG2, x2, c, x}; and then use a comma-separated list: fitFunctionHan...

How do I call a function handle with an vector - rather than a list of arguments

Easy: first define a cell array: C = {a1Init, wG1, x1,a2, wG2, x2, c, x}; and then use a comma-separated list: fitFunctionHan...

1 day ago | 0

Answered

Load data from mat files to a matrix

N = 50; C = cell(1,N); for k = 1:N F = sprintf('%d.mat',k); S = load(F); C{k} = S.Data(:,3); end M = [C{:}] ...

Load data from mat files to a matrix

N = 50; C = cell(1,N); for k = 1:N F = sprintf('%d.mat',k); S = load(F); C{k} = S.Data(:,3); end M = [C{:}] ...

1 day ago | 0

Answered

how to insert a value into the array in a consistent manner.

>> A = ones(3,1); >> A(end+1) = 0; >> A([2:end,1]) = A A = 0 1 1 1

how to insert a value into the array in a consistent manner.

>> A = ones(3,1); >> A(end+1) = 0; >> A([2:end,1]) = A A = 0 1 1 1

1 day ago | 0

| accepted

Answered

Code overwrites results in for loop. Cannot figure out how to index.

Either alpha_beta(k,1) = first_data(1); alpha_beta(k,2) = first_data(3); or alpha_beta(k,1:2) = first_data([1,3]); And reme...

Code overwrites results in for loop. Cannot figure out how to index.

Either alpha_beta(k,1) = first_data(1); alpha_beta(k,2) = first_data(3); or alpha_beta(k,1:2) = first_data([1,3]); And reme...

2 days ago | 0

Answered

Index exceeds the number of array elements (35).

You have repeatedly used syntax with an = sign, which assigns those values to some variables, e.g: xlabel=('estimated time--->'...

Index exceeds the number of array elements (35).

You have repeatedly used syntax with an = sign, which assigns those values to some variables, e.g: xlabel=('estimated time--->'...

3 days ago | 0

Answered

Understanding Figure Windows & Changing Their Apperances

"Why cannot i amend the Number property?" Because the 'Number' property is read only: https://www.mathworks.com/help/matlab/re...

Understanding Figure Windows & Changing Their Apperances

"Why cannot i amend the Number property?" Because the 'Number' property is read only: https://www.mathworks.com/help/matlab/re...

4 days ago | 0

| accepted

Answered

How do I change the values of rows in specific columns based on another table which serves as a lookup?

>> A = [2001,2001;2001,2003;2001,2005;2001,2006] A = 2001 2001 2001 2003 2001 2005 2001 2006 >> B = [1...

How do I change the values of rows in specific columns based on another table which serves as a lookup?

>> A = [2001,2001;2001,2003;2001,2005;2001,2006] A = 2001 2001 2001 2003 2001 2005 2001 2006 >> B = [1...

6 days ago | 0

| accepted

Answered

How do I locate all integer values within a matrix (of string and integer values in the same cell), then replace all those integer values with a 1 or 0 thus forming a new matrix with the replaced integers?

Method one: multiple regular expressions in one regexprep call: >> c = {'( x(2) | x(1) )', 'x(3)', '( x(4) | x(6) | x(5) )', '(...

How do I locate all integer values within a matrix (of string and integer values in the same cell), then replace all those integer values with a 1 or 0 thus forming a new matrix with the replaced integers?

Method one: multiple regular expressions in one regexprep call: >> c = {'( x(2) | x(1) )', 'x(3)', '( x(4) | x(6) | x(5) )', '(...

8 days ago | 1

Answered

Averaging 30 arrays into one using function

Do not create lots of separate variables or arrays, just use the split-apply process: https://www.mathworks.com/help/matlab/mat...

Averaging 30 arrays into one using function

Do not create lots of separate variables or arrays, just use the split-apply process: https://www.mathworks.com/help/matlab/mat...

8 days ago | 0

Answered

Dont know how to name this...

MATLAB only accepts decimal point , and does NOT accept a decimal comma. When you write a comma you are writing two separate va...

Dont know how to name this...

MATLAB only accepts decimal point , and does NOT accept a decimal comma. When you write a comma you are writing two separate va...

8 days ago | 1

| accepted

Answered

Please help me to understand Error "The expression to the left of the equals sign is not a valid target for an assignment.

The problem is your invented syntax using { and }, which looks like you are trying to write code using a different programming l...

Please help me to understand Error "The expression to the left of the equals sign is not a valid target for an assignment.

The problem is your invented syntax using { and }, which looks like you are trying to write code using a different programming l...

9 days ago | 2

| accepted

Answered

How to read specific parts of file and then write it to a text file?

This imports all of the "TEC MAP" data from the file you uploaded: str = fileread('codg1520.14i'); % Functions to convert text...

How to read specific parts of file and then write it to a text file?

This imports all of the "TEC MAP" data from the file you uploaded: str = fileread('codg1520.14i'); % Functions to convert text...

9 days ago | 0

| accepted

Submitted

MatPlotLib Perceptually Uniform Colormaps

MatPlotLib's default perceptually uniform colormap VIRIDIS and distinctive ColorOrder TAB10/VEGA10

9 days ago | 70 downloads |

Answered

Minimum value of loop

>> N = 3; >> a = Inf; >> for k = 1:N, a = min(a,k+2); end >> a a = 3

Minimum value of loop

>> N = 3; >> a = Inf; >> for k = 1:N, a = min(a,k+2); end >> a a = 3

10 days ago | 0

| accepted

Answered

How to concatenate all these cells vertically?

>> load('matlab.mat') >> R = S.result; >> T = vertcat(R{:}); >> whos T Name Size Bytes Class Attr...

How to concatenate all these cells vertically?

>> load('matlab.mat') >> R = S.result; >> T = vertcat(R{:}); >> whos T Name Size Bytes Class Attr...

10 days ago | 1

| accepted

Answered

Creating a tridiagonal matrix

"My teacher has said that the best way to go about it is using loops" Why on earth would they say that? Either diag : >> N = 1...

Creating a tridiagonal matrix

"My teacher has said that the best way to go about it is using loops" Why on earth would they say that? Either diag : >> N = 1...

11 days ago | 1

Answered

split a string by a set of pre-defined number of characters rather than any delimiter

You could do that using regular expressions: >> S1 = ' 961.666 - Psat 1.0000 45.0971 3.6734';...

split a string by a set of pre-defined number of characters rather than any delimiter

You could do that using regular expressions: >> S1 = ' 961.666 - Psat 1.0000 45.0971 3.6734';...

14 days ago | 0

| accepted

Answered

removing non prime number function

str = fileread('temp.txt'); vec = str2double(regexp(str,'\d+','match')) [fid,msg] = fopen('output.txt','wt'); assert(fid>=3,m...

removing non prime number function

str = fileread('temp.txt'); vec = str2double(regexp(str,'\d+','match')) [fid,msg] = fopen('output.txt','wt'); assert(fid>=3,m...

14 days ago | 0

Answered

Repeat the value of a variable to match the length of another variable

>> X = 'TESTING'; >> Y = 'WORLD'; >> Z = Y(1+mod(0:numel(X)-1,numel(Y))) Z = WORLDWO

Repeat the value of a variable to match the length of another variable

>> X = 'TESTING'; >> Y = 'WORLD'; >> Z = Y(1+mod(0:numel(X)-1,numel(Y))) Z = WORLDWO

14 days ago | 0

Answered

Substract Matrix coloum-wise from Matrix without using a loop

permute lets you do this on one line: D = min(sqrt(sum(bsxfun(@minus,permute(A,[1,3,2]),permute(B,[3,1,2])).^2,3)),[],1); And ...

Substract Matrix coloum-wise from Matrix without using a loop

permute lets you do this on one line: D = min(sqrt(sum(bsxfun(@minus,permute(A,[1,3,2]),permute(B,[3,1,2])).^2,3)),[],1); And ...

14 days ago | 0

| accepted

Answered

Is MATLAB confusing functions and arrays?

"Is MATLAB confusing functions and arrays?" That can happen in certain circumstances, but that does not seem to be the case her...

Is MATLAB confusing functions and arrays?

"Is MATLAB confusing functions and arrays?" That can happen in certain circumstances, but that does not seem to be the case her...

15 days ago | 1

| accepted

Answered

Storing user inputs during while loop, in a vector

x = []; while ... x(end+1) = input(prompt); end

Storing user inputs during while loop, in a vector

x = []; while ... x(end+1) = input(prompt); end

16 days ago | 0

Answered

find elements vector in a matrix

Simply use sub2ind like this: >> idx = sub2ind(size(psic_pos),1:size(psic_pos,1),loc); >> vec = psic_pos(idx) vec = 0....

find elements vector in a matrix

Simply use sub2ind like this: >> idx = sub2ind(size(psic_pos),1:size(psic_pos,1),loc); >> vec = psic_pos(idx) vec = 0....

16 days ago | 1

| accepted

Answered

find 4d matrix positions

"I tried with ind2sub but it was useless." It worked for me. First lets define some fake data: >> A = zeros(5,4,3,2); >> A(5,...

find 4d matrix positions

"I tried with ind2sub but it was useless." It worked for me. First lets define some fake data: >> A = zeros(5,4,3,2); >> A(5,...

16 days ago | 0

| accepted

Answered

import data without header

opt = {'HeaderLines',20}; fmt = repmat('%f',1,4); str = fileread('temp0.txt'); C = textscan(strrep(str,',','.'),fmt,opt{:}); ...

import data without header

opt = {'HeaderLines',20}; fmt = repmat('%f',1,4); str = fileread('temp0.txt'); C = textscan(strrep(str,',','.'),fmt,opt{:}); ...

16 days ago | 0

| accepted

Answered

Extract number from file name

>> C = {'K10_0.0.json', 'Mig_Thresh_2.0.json', 'K_5_6.5.json', 'WC_0.00051.json'}; >> [~,N] = cellfun(@fileparts,C,'uni',0); >...

Extract number from file name

>> C = {'K10_0.0.json', 'Mig_Thresh_2.0.json', 'K_5_6.5.json', 'WC_0.00051.json'}; >> [~,N] = cellfun(@fileparts,C,'uni',0); >...

17 days ago | 1