Answered
Does this variable exist
For structures: https://www.mathworks.com/help/matlab/ref/isfield.html For tables: https://www.mathworks.com/matlabcentral/an...

6 years ago | 0

| accepted

Answered
Polar to cartesian conversion problem
"but something goes wrong because if I convert it back (from cartesian to polar) I don't get the same results" Nothing goes wro...

6 years ago | 0

| accepted

Answered
Choosing specific columns and rows
Y = S.data(...); ^^ you need to access the field of structure S https://www.mathworks.com/help/matlab/matlab_prog/access-d...

6 years ago | 0

| accepted

Answered
How can I add zeros between elements of a matrix?
>> A = [1,2,3]; Method one: indexing: >> B = zeros(size(A).*[1,2]); >> B(1:2:end) = A B = 1 0 2 0 3 0 Method ...

6 years ago | 2

Answered
Find consecutive number of specific length in a vector
>> n = 5; >> x = [10,10,10,10,11,11,11,11,11,12,12,13,13,13,13,13]; >> f = find([true,diff(x)~=0,true]); >> d = diff(f)==n; ...

6 years ago | 1

| accepted

Answered
How to adapt a script to go through different subfolders?
Both of your loops suffer the same problem: you delete only the last file. This is because after the loop you use the loop itera...

6 years ago | 0

| accepted

Answered
Plot marker on points not specified within the vector
You might think this is easy, but there is no simple, general solution for an arbitrary (i.e. non-monotonic) function and an arb...

6 years ago | 0

| accepted

Answered
markers not getting joined in plot
You are plotting scalar values in a loop, which will show individual markers unconnected by a line. If you want to have markers...

6 years ago | 0

| accepted

Answered
Replacing the minimum of a vector
" It seems random, but that doesn't make sense." It is not random, and it makes perfect sense. According to the min documentat...

6 years ago | 0

| accepted

Answered
Split cell arrays into seperate matrix; Indexing problem with cell array
"Maybe you could help me with a neat solution" The neat solution is to use MATLAB's arrays effectively. For example, something ...

6 years ago | 1

| accepted

Answered
Reduce string length after check, with one line
x = x(1:min(5,end))

6 years ago | 0

| accepted

Answered
Fast method for findings which rows of a matrix are contained in another
>> A = [1,2,3,4;5,6,7,8;9,10,11,12] A = 1 2 3 4 5 6 7 8 9 10 11 12 >> B = [...

6 years ago | 1

| accepted

Answered
Aligning columns with fprintf
You can use '%g' to print values with trailing zeros removed: X = 0.5:0.5:2.5; Y = 500:250:1500; M = [425,1441,2651,3665,4091...

6 years ago | 0

| accepted

Answered
Open multiple files from the same folder with fopen and textscan
Following the examples in the documentation: https://www.mathworks.com/help/matlab/import_export/process-a-sequence-of-files.ht...

6 years ago | 0

Answered
A point charge of Q = 5 nC is located at (2,2,8). how to find the distance of the electric fields generated by the charge over the range of 0 < x < 4 m, 0 < y < 4 m, and 0 < z < 4 m due to the point charge?
>> [xA,yA,zA] = ndgrid(x,y,z); >> rA = sqrt( (xA-2).^2 + (yA-2).^2 + (zA-8).^2 ); Of course rA will actually have size numel(x...

6 years ago | 0

| accepted

Answered
Cell array summation when arrays are different sizes
Without any padding with extra zeros/NaN/etc. Generate some indices to use accumarray to sum only the required elements: >> in...

6 years ago | 1

| accepted

Answered
How to remove first consonant/consonant cluster and add it to the end?
>> a = {'desk', 'hello', 'cup', 'switch', 'smith', 'flowers', 'angry', 'decorations'}; >> regexprep(a,'(^[^aeiou]+)(.+)','$2$1'...

6 years ago | 0

Answered
Find last row of csv contents using fopen, fgetl?? Or, another way?
Use feof like this: while ~feof(fid); tline = fgetl(fid); ... end

6 years ago | 0

| accepted

Answered
Best way to pass large amounts of variables between functions
"What would be the best way to pass variables between functions?" There is no simple answer because it depends on the nature of...

6 years ago | 1

| accepted

Answered
Defining table reference using list contents
Dragging-and-dropping into MATLAB actually makes your task harder, because it creates lots of separate variables. Drag-and-drop ...

6 years ago | 0

| accepted

Answered
How to parse a file with value pairs
This works with the attached file (which I had to create myself): T = table(); [fid,msg] = fopen('temp0.txt','rt'); assert(fi...

6 years ago | 0

| accepted

Answered
Excercises for MATLAB programmimg
"Should I assume that there is no web portal that offers questions like that" This one: https://projecteuler.net/

6 years ago | 0

Answered
Input arguments to function include colon operator. To input the colon character, use ':' instead.
The function mycon3 is not correctly defined. The fmincon documentation states that its optional nonlcon input argument should ...

6 years ago | 1

| accepted

Answered
Rearranging dates to make them suitable for datetime format
>> C = {'08/21/2020 (Aug)';'05/26/2018 (May)';'04/03/2016';'02/06/2005 (QQ)'}; >> D = datetime(regexp(C,'^.{10}','match','once'...

6 years ago | 1

| accepted

Answered
How can i open the attached text file or other formate file given in community in my own matlab
"How can i open the attached text file..." Download the file, then run either: V = dlmread('Xc.txt'); or V = readmatrix('Xc....

6 years ago | 0

| accepted

Answered
Vectorisation of a loop
X = X1+[0;cumsum(Vx(1:end-1).*diff(T))] Y = Y1+[0;cumsum(Vy(1:end-1).*diff(T))]

6 years ago | 0

| accepted

Answered
nchoosek with multiple arrays
Simply generate a matrix of indices: idx = nchoosek(1:33,3); and then for each row in that matrix perform your calculations, w...

6 years ago | 0

| accepted

Answered
How to convert matrix format
You do not give enough information about the order you want the elements to be in, but this should get you started: >> B = resh...

6 years ago | 1

| accepted

Answered
extract data from cell array based on matching numbers with location in array
Where C is your cell array of data: B = C(A) https://www.mathworks.com/help/matlab/math/array-indexing.html https://www.mathw...

6 years ago | 1

| accepted

Answered
Removing repeated numbers in a matrix
>> A = [9,9,1,1,2,2,2,2,2,0,3,3;7,7,4,4,4,5,5,6,6,6,6,6;8,8,7,7,7,8,8,8,9,9,9,5] A = 9 9 1 1 2 2 2 2 2 0 ...

6 years ago | 2

| accepted

Load more