Answered

Duplicate elements in array n times, where n is an array itself

A = [1 2 3] B = [2 3 1] C=cell2mat(arrayfun(@(x,y) repmat(x,1,y),A,B,'un',0))

Duplicate elements in array n times, where n is an array itself

A = [1 2 3] B = [2 3 1] C=cell2mat(arrayfun(@(x,y) repmat(x,1,y),A,B,'un',0))

6 years ago | 1

Answered

create day month and year

d1=datenum('01-01-1971','dd-mm-yyyy') d2=datenum('31-12-1971','dd-mm-yyyy') d=datevec(d1:d2) d=d(:,1:3)

create day month and year

d1=datenum('01-01-1971','dd-mm-yyyy') d2=datenum('31-12-1971','dd-mm-yyyy') d=datevec(d1:d2) d=d(:,1:3)

6 years ago | 2

Answered

Time conversion in a table

a=[1010, NaN, 1256, NaN, 1345] idx=isnan(a) a(idx)=0 out=arrayfun(@(x) datestr(datenum(sprintf('%04d',x),'HHMM') ,'HH:MM') ...

Time conversion in a table

a=[1010, NaN, 1256, NaN, 1345] idx=isnan(a) a(idx)=0 out=arrayfun(@(x) datestr(datenum(sprintf('%04d',x),'HHMM') ,'HH:MM') ...

6 years ago | 1

| accepted

Answered

How to extract a specific 3 digit number from a filename?

s='hst_05773_05_wfpc2_f502n_wf_sci.tif' out=regexp(s,'(?<=_f)\d{3}','match','once') or s='hst_05773_05_wfpc2_f502n_wf...

How to extract a specific 3 digit number from a filename?

s='hst_05773_05_wfpc2_f502n_wf_sci.tif' out=regexp(s,'(?<=_f)\d{3}','match','once') or s='hst_05773_05_wfpc2_f502n_wf...

6 years ago | 1

| accepted

Answered

how to display output in matlab as table enclosed below

h={'count' 'x' 'f(x)' 'initial'} data=[2 1 -0.307799 0.00 3 0.544459 0.0153522 ...

how to display output in matlab as table enclosed below

h={'count' 'x' 'f(x)' 'initial'} data=[2 1 -0.307799 0.00 3 0.544459 0.0153522 ...

6 years ago | 2

Answered

Easy question converting numbers to hours

datestr(datenum(sprintf('%04d',1156),'HHMM') ,'HH:MM') Or a=sprintf('%04d',1156) a=sprintf('%s:%s',a(1:2),a(3:4))

Easy question converting numbers to hours

datestr(datenum(sprintf('%04d',1156),'HHMM') ,'HH:MM') Or a=sprintf('%04d',1156) a=sprintf('%s:%s',a(1:2),a(3:4))

6 years ago | 0

| accepted

Answered

Efficient method of searching cell array for multiple, partial (non exact) strings

*edit* MasterList = {'dog' 'house' 'hotdog' 'cat' 'house music' 'banana' 'that actor from the 80s'}; SearchFor = {'dog' 'h...

Efficient method of searching cell array for multiple, partial (non exact) strings

*edit* MasterList = {'dog' 'house' 'hotdog' 'cat' 'house music' 'banana' 'that actor from the 80s'}; SearchFor = {'dog' 'h...

6 years ago | 1

Answered

hello, i have 5 input as following , how to use print command as print(' a= ' a , ' b= ' b, ' c= ' c, ' d= ' d,' e= ' e) in order to display output a=3 b =4 c=6 d=7 e=9

str={'a','b','c','d'} v={3 4 5 6} w=[str; v] sprintf('%s=%d;',w{:})

hello, i have 5 input as following , how to use print command as print(' a= ' a , ' b= ' b, ' c= ' c, ' d= ' d,' e= ' e) in order to display output a=3 b =4 c=6 d=7 e=9

str={'a','b','c','d'} v={3 4 5 6} w=[str; v] sprintf('%s=%d;',w{:})

6 years ago | 0

Answered

Unable to store the persistent variable

function out =exp_average(in,b) persistent average weight if isempty(weight) %It does not already exist weight = 0.1; ...

Unable to store the persistent variable

function out =exp_average(in,b) persistent average weight if isempty(weight) %It does not already exist weight = 0.1; ...

6 years ago | 1

| accepted

Answered

Simple read-in to matrix, vector

If you want to use your code, you have to know that fgetl load the line as a string, you need to convert it to double fid =...

Simple read-in to matrix, vector

If you want to use your code, you have to know that fgetl load the line as a string, you need to convert it to double fid =...

6 years ago | 0

Answered

Simple read-in to matrix, vector

d=importdata('file.txt') n=d(1) M=reshape(d(2:2+n*n-1),n,n)' v=d(end-n+1:end)

Simple read-in to matrix, vector

d=importdata('file.txt') n=d(1) M=reshape(d(2:2+n*n-1),n,n)' v=d(end-n+1:end)

6 years ago | 0

Answered

why stateflow during never execute?

There is an unconditional transition from B to C, which means there is no during action. But you can see the action in B when yo...

why stateflow during never execute?

There is an unconditional transition from B to C, which means there is no during action. But you can see the action in B when yo...

6 years ago | 0

Answered

Count and "synchronize" events in several columns

idx=any(A(:,2:end)==1,2)' [~,~,ii]=unique(nonzeros(cumsum(~idx).*idx)) c=nan(size(A(:,1))) c(logical(idx))=ii out=[A c] ...

Count and "synchronize" events in several columns

idx=any(A(:,2:end)==1,2)' [~,~,ii]=unique(nonzeros(cumsum(~idx).*idx)) c=nan(size(A(:,1))) c(logical(idx))=ii out=[A c] ...

6 years ago | 0

Answered

How do i specify the sample time of an Inport block simulink in 'milliseconds' programmatically from Matlab

You can't change it, and there is no need to do it. If you want a millisecond, just multiply it by 0.001

How do i specify the sample time of an Inport block simulink in 'milliseconds' programmatically from Matlab

You can't change it, and there is no need to do it. If you want a millisecond, just multiply it by 0.001

6 years ago | 0

| accepted

Answered

Count and "synchronize" events in several columns

A=[1 NaN NaN NaN 2 NaN NaN NaN 3 1 NaN NaN 4 1 1 NaN 5 NaN NaN NaN 6 NaN NaN NaN 7 NaN 1 NaN ...

Count and "synchronize" events in several columns

A=[1 NaN NaN NaN 2 NaN NaN NaN 3 1 NaN NaN 4 1 1 NaN 5 NaN NaN NaN 6 NaN NaN NaN 7 NaN 1 NaN ...

6 years ago | 1

Answered

run the for loop only once Matlab

If you want to run it once, then don't use a for loop, to increment ii, use ii=mod(ii,4)+1 don't use i, it's used to rep...

run the for loop only once Matlab

If you want to run it once, then don't use a for loop, to increment ii, use ii=mod(ii,4)+1 don't use i, it's used to rep...

6 years ago | 0

| accepted

Answered

Attempted to access x(1,2); index out of bounds because size(x)=[105760,1].

From the error message, it appears that your variable x is a a column vector 105760x1 . In your code you are trying to access x(...

Attempted to access x(1,2); index out of bounds because size(x)=[105760,1].

From the error message, it appears that your variable x is a a column vector 105760x1 . In your code you are trying to access x(...

6 years ago | 0

| accepted

Answered

Search for files in directory

d='E:\' % your directory f=dir(fullfile(d,'test.txt'))

Search for files in directory

d='E:\' % your directory f=dir(fullfile(d,'test.txt'))

6 years ago | 0

Answered

Index exceeds matrix dimensions

This has nothing to do with the dimension, look at this example A=[1 1;2 2] You can write it as you want A(:,:,1,1,...

Index exceeds matrix dimensions

This has nothing to do with the dimension, look at this example A=[1 1;2 2] You can write it as you want A(:,:,1,1,...

6 years ago | 0

Answered

I need to find 10000 ramdom # in the range of (0.078,0.0078) for mass and (2, 0.1) for diameter. Then calculate the density of the 10k and do a histogram of them. Can anybody help me please?. This is what I got so far but is not working.

You mean in the range of [0.0078 0.078] not [0.078, 0.0078], because 0.0078 is less then 0.078. a1 = 0.078; b1 = 0.0078; ...

I need to find 10000 ramdom # in the range of (0.078,0.0078) for mass and (2, 0.1) for diameter. Then calculate the density of the 10k and do a histogram of them. Can anybody help me please?. This is what I got so far but is not working.

You mean in the range of [0.0078 0.078] not [0.078, 0.0078], because 0.0078 is less then 0.078. a1 = 0.078; b1 = 0.0078; ...

6 years ago | 0

Answered

use a loop structure .

This can be done without a for loop [m,n]=ndgrid(1:4); A=m*10+n

use a loop structure .

This can be done without a for loop [m,n]=ndgrid(1:4); A=m*10+n

6 years ago | 0

Answered

How to convert a numeric array to a table.I want the first row of data of the array to be J and the second row of data to be K in a table T[J K];

A=randi(10,2,5) names={'J','K'} cell2table(num2cell(A'),'VariableNames',names)

How to convert a numeric array to a table.I want the first row of data of the array to be J and the second row of data to be K in a table T[J K];

A=randi(10,2,5) names={'J','K'} cell2table(num2cell(A'),'VariableNames',names)

6 years ago | 0

Answered

Finding second smallest element in a row.

X = [441 137 594 507 417 581 312 362 263 151 472 512 129 70 298 255 442 574 289 157 0]; out=min(setdiff(X,min(X))) or ...

Finding second smallest element in a row.

X = [441 137 594 507 417 581 312 362 263 151 472 512 129 70 298 255 442 574 289 157 0]; out=min(setdiff(X,min(X))) or ...

6 years ago | 5

| accepted

Answered

Find Nonzero element of a signal in simulink - without using "Find" block

You can use compare to zero block <</matlabcentral/answers/uploaded_files/58497/ans12.jpg>>

Find Nonzero element of a signal in simulink - without using "Find" block

You can use compare to zero block <</matlabcentral/answers/uploaded_files/58497/ans12.jpg>>

6 years ago | 0

Answered

How to select columns in a matrix of variable size?

m=size(A,2) B=A(:,1:3:m) C=A(:,setdiff(1:m,1:3:m))

How to select columns in a matrix of variable size?

m=size(A,2) B=A(:,1:3:m) C=A(:,setdiff(1:m,1:3:m))

6 years ago | 0

| accepted

Answered

Find first non-zero column of a matrix

A=randi([0 2],20,8) [~,out]=max(sum(logical(A)))

Find first non-zero column of a matrix

A=randi([0 2],20,8) [~,out]=max(sum(logical(A)))

6 years ago | 2

Answered

extracting values from text files as matrix format

fid=fopen('file.txt') s=fgetl(fid) out={} while ischar(s) out{end+1}=regexp(s,'(?<=(ID:|Health:| Eccentricity:))\s+\S...

extracting values from text files as matrix format

fid=fopen('file.txt') s=fgetl(fid) out={} while ischar(s) out{end+1}=regexp(s,'(?<=(ID:|Health:| Eccentricity:))\s+\S...

6 years ago | 0

| accepted

Answered

I want to find the x and y values of f(x,y) when f(x,y) is a minimum over x = -1:0.001:1 and y = -1:0.001:1.

x=-1:0.001:1 y=x [ii,jj]=ndgrid(x,y] z=sin(ii)+cos(jj) % Example [min_val,index]=min(z) xidx=x(index) yidx=y(index)

I want to find the x and y values of f(x,y) when f(x,y) is a minimum over x = -1:0.001:1 and y = -1:0.001:1.

x=-1:0.001:1 y=x [ii,jj]=ndgrid(x,y] z=sin(ii)+cos(jj) % Example [min_val,index]=min(z) xidx=x(index) yidx=y(index)

6 years ago | 2

| accepted

Answered

Matlab on iOS without computer session

<http://www.mathworks.com/videos/matlab-mobile-for-android-overview-72032.html>

Matlab on iOS without computer session

<http://www.mathworks.com/videos/matlab-mobile-for-android-overview-72032.html>

6 years ago | 0