Answered
'Array indices must be positive integers or logical values' error for directory use
"I have been told by my lecturer that continuously using the csvread(files(i).name) function will slow down my code as it has to...

8 years ago | 0

| accepted

Answered
Non-singleton dimensions of the two input arrays must match each other using bsxfun
The problem lies in the last dimension (here I marked the first three dimensions with r,c,p because their actual numeric values ...

8 years ago | 0

| accepted

Answered
How to compare 5 cell arrays and get their contents in one cell array?
Use ismember in a loop: C0 = {'A';'B';'C';'D';'F'}; % your 600x1 cell array. C1 = {'A',1;'C',123;'X',0}; C2 = {'B',21;'D',222...

8 years ago | 2

| accepted

Answered
if + for loops vs while loop. Same good different results
Work backwards from the end, and look at where the time / T value last changes. They are not the same. The location of the the i...

8 years ago | 1

| accepted

Answered
Vector multiplication in equation
Use parentheses to group the denominator together, and use the correct division operator: x=sqrt((a*b*c)./(d*e*f)) And tested:...

8 years ago | 3

Answered
How to get the original Image matrix from the Integral Image of a N*N matrix?
A simple solution based on the explanation given on the integralImage help page: >> II = [0,0,0,0,0;0,1,3,6,10;0,6,14,24,36;0,1...

8 years ago | 1

| accepted

Answered
how to sum the elements of the same row in a cell array?
>> C = {'A','hello';'B','live';'C','cat';'A','world';'B','fast'}‡ C = 'A' 'hello' 'B' 'live' 'C' 'cat'...

8 years ago | 0

| accepted

Answered
Conversion of a string back to an existing vector name for assigning data
As Guillaume and I wrote in comments to your question, the best solution is to avoid this situation entirely. If you find yourse...

8 years ago | 1

Answered
File formatting in Matlab
>> M = dlmread('temp0.txt'); >> M = M.'; >> dlmwrite('temp1.txt',M(:)) The test files are attached.

8 years ago | 0

Answered
Sortrows alternative / matrix sorting
function [A,B] = mysortdata(A,B) M = qsRecFun([A;B]); A = M(1,:); B = M(2,:); end function M = qsRecFun(M) N = size(M,2); ...

8 years ago | 1

| accepted

Answered
How can I create a new matrix by using existing values in a column?
Simpler and much more efficient to use toeplitz: >> B = [0.100;0.250;0.200;0.120;0.080;0.060;0.055;0.040;0.020]; >> C = zeros(...

8 years ago | 2

| accepted

Answered
Compute differences bewteen vectors in a matrix
This is easy to achieve with basic indexing and an anonymous function: >> A = randi(9,5,7) A = 4 4 5 9 4 7 1 ...

8 years ago | 0

| accepted

Answered
Question Regarding Sorting of the elements
>> X1 = [ 4 2 6]; >> V1 = [ 5 9 1]; >> X2 = [ 1 5 3]; >> V2 = [ 0 0 0]; >> X(X1) = V1; >> X(X2) = V2 X = 0 9 0 5...

8 years ago | 0

Answered
How to sort a matrix with the second row depending on the sorting of the first row?
One easy way to obtain indices from any sorting algorithm is to "hang" some indices onto the data before sorting, and apply exac...

8 years ago | 1

| accepted

Answered
I want to use all the values present in two arrays but if I run for loops (ie) I used two for loops but only the last value of both the arrays are taken. What is the syntax so that I can use all my values of both arrays simultaneously.?
V1 = [60,78,132,12,26,10,150,156,172,168,159,174]; V2 = [61,150,16,24,25,8,155,164,173,160,171,169]; V3 = [0,1,2,3,4,5,6,7,8,9...

8 years ago | 0

| accepted

Answered
Assign values to a new variable via a function
"% Below line is the line that doesn't work" namesNew = namesOld; It doesn't work because you are trying to magically access v...

8 years ago | 0

| accepted

Answered
How to save/load cell data in/from matlab binary file with another extension?
>> A = 1; >> save('test.xyz','A','-mat') >> clear >> S = load('test.xyz','-mat'); >> S.A ans = 1

8 years ago | 1

| accepted

Answered
how to convert 5.5 hour to 05:30:00 HH:MM:SS format?
>> datestr(5.5/24,'HH:MM:SS') ans = 05:30:00

8 years ago | 1

| accepted

Answered
storing values from a for loop into a new variable
N = numel(row); C = cell(1,N); for k = 1:N C{k} = sol{k} end Or without a loop: C = sol(1:N)

8 years ago | 0

| accepted

Answered
How to concatenate structs with different fieldnames?
Just use some loops (this will be quite efficient): A(1).Stats.Var1 = 1; A(1).Stats.Var2 = 2; A(2).Stats.Var1 = 3; Z = repma...

8 years ago | 0

| accepted

Answered
How to read .csv file using textscan function ?
opt = {'Delimiter',',','CollectOutput',true,'TreatAsEmpty','""'}; fmt = repmat('%f',1,50); fmt = ['%q%q',fmt]; [fid,msg] = fo...

8 years ago | 1

| accepted

Answered
plot mean of vector v(1:i)
plot(v,cumsum(v)./(1:numel(v)))

8 years ago | 0

| accepted

Answered
How to sort 2 matching column only decending one of them?
Either put the data into one matric and sort by one column, e.g.: M = [T(:),H(:)]; % [period,height] M = sortrows(M,-2) % so...

8 years ago | 0

| accepted

Answered
Print the power of a vehicle with time array entries
>> m = 1500; >> g = 9.81; >> a = 0; >> p = 1.2; >> cd = 0.17; >> A = 0.66; >> mi = 0.54; >> htta = 0.45; >> ...

8 years ago | 0

| accepted

Answered
How to measure the euclidean difference between a vector and a matrix?
Without the statistics toolbox: >> f = [3,9;4,10;8,1]; >> m = [4,8]; >> sqrt(sum((m-f).^2,2)) ans = 1.4142 2.0000 ...

8 years ago | 1

| accepted

Answered
Which commands will I use to generate the following plot
Using simple numeric commands: >> X = -5:0.1:+5; >> Y = 1-X.^3; >> plot(X,Y)

8 years ago | 1

Answered
minmax does not work in matlab 2018b
https://www.mathworks.com/help/deeplearning/ref/minmax.html is simply equivalent to: [min(M,[],2),max(M,[],2)] for a matrix M...

8 years ago | 1

| accepted

Answered
How can I access the elements of one array with another array?
This is really very easy once you put those indices into a cell array: C = {ix,iy,...,iN,':'}; a(C{:}) = b https://www.mathwo...

8 years ago | 2

| accepted

Answered
What is the difference between Function and Function Handle?
A function is some code written in a file, starting with the function keyword. When you call that function then MATLAB will run ...

8 years ago | 3

| accepted

Answered
Reading multiple nc files in different subfolders within a directory
You should start again, because all of those cd calls are absolute chaos. Start with something like this: D = '/Users/Document...

8 years ago | 0

| accepted

Load more