Delete cells from cell array without replacing that by NULL [duplicate] - matlab

This question already has answers here:
Delete a cell array column
(3 answers)
Closed 9 years ago.
I have a cell which contains cells, I want to delete specific cell from the cell array but with 'delete' function I am getting error as "Argument must contain a string".
For example I have a cell A= { ['a'] ['b'] ['c'] [1 2 3]} now i want to delete the 3rd value of A that is A(3)='c' such that the new cell A after deleting A(3) will be as A={ ['a'] ['b'] [1 2 3]}, means there should not be any null value at the place of deleted value as A={['a'] ['b'] [] [1 2 3]} .
Please solve my problem.

Use parenthesis instead of braces:
A(1) = [];

Related

How to do multiple where query without effect data in TypeORM?

I want to do multiple where query without effect data. I want to get data that include at least 1 data per array. Pseudo code
data =[1,3]
array1 = [1,2]
array2 = [3,4]
if(data.IsIntersect(array1) and data.IsIntersect(array2))
IsIntersect checks are there a intersection beetween arrays
I did so far
queryBuilder.andWhere(
'properties.id IN (:...sizeIds) AND properties.id IN (:...colorIds)',
{ sizeIds: [1, 2], colorIds: [3, 4] },
);
It returns empty because firstly checks properties for 'sizeIds' then it checks for 'colorIds'. For example
properties includes 1,3
check for sizeIds, returns 1
check for colorIds, return empty
How can I do that with typeORM?
How can properties.id be 1 and 3? And if it is, how could 1 or 3 be in both? You're asking for the impossible.
I assume you mean to ask for when properties.id is 1 or 3, because if it is [1,3] then you should use the postgres array syntax {1,3} & the ANY keyword (some variation on this: Check if value exists in Postgres array).
tldr, I think all you need is brackets and OR instead of AND:
queryBuilder.andWhere(
'(properties.id IN (:...sizeIds) OR properties.id IN (:...colorIds))',
{ sizeIds: [1, 2], colorIds: [3, 4] },
);
If properties.id is in fact an array, then please add the entity definition to your question. If you want to merge the rows where properties.id is in the list you will need a GROUP BY (https://orkhan.gitbook.io/typeorm/docs/select-query-builder).

How to call a value from cell of array in matlab? [duplicate]

This question already has an answer here:
Access to a vector in cell in Matlab
(1 answer)
Closed 5 years ago.
i have this cell array in my Matlab code
energie{n} = [Ea, Ed];
In which Ea contain 1 value and Ed contain 3 values i don't know how to call the second value of Ed .
For example if i have this
Ea =
50.9982
Ed =
1.1777 19.0690 20.2442 8.5108
and i want to call '19.0690' how can i do it ?
I tried this
ans=energie{1:n:3}
but it give me
50.9982 1.1777 19.0690 20.2442 8.5108
Also i tried
energie{n}{2}(3)
But i got this error message
"Cell contents reference from a non-cell array object."
energie{n} is a 5 element matrix. You are wanting the 3rd element of it, so energie{n}(3) will give you the element.
If you had done energie{n} = {Ea Ed} then energie{n} is a cell array containing 2 elements, where the first element is a scalar and the second element is a 4 element vector. In this case energie{n}{2}(2) would work.

How to compare two vectors element by element? [duplicate]

This question already has answers here:
How do I compare all elements of two arrays?
(3 answers)
Closed 6 years ago.
I have two matrices: A=[1,2,3,4,5] and B=[1,2,3,4,6]. I need to compare elements of those matrix, and as a result I need to have binary matrix
Result=[1,1,1,1,0], that means if A(i)==B(i) then Result(i)=1 else Result(i)=0.
I have tried with:
if (isequal (A,B))
Result=1
else
Result=0
end
I have tried: Result=sign(A,B)
I hope that you could help me please?
A = [1,2,3,4,5]
B = [1,2,3,4,6]
Result = A == B

Remove specific integers from matrix [duplicate]

This question already has answers here:
Exclude elements from array [duplicate]
(3 answers)
Closed 6 years ago.
I have a matrix <1x1000> containing integers. It contain the value 150 a couple of times and I want to remove that value completely. Any ideas how to?
Help is much appreciated!
If you want to remove all elements that equal 150 then
M = M(M ~= 150)
If you want to remove all elements belonging to a list of undesired numbers then
list = [150, 230, 420]
M = M(~ismember(M, list))
Same but different expression
M(M==150)=[];
list = [150,230,420];
M(ismember(M,list))=[];
When you type A(index)=[], it delete A(index). For example,
A = [1,2,3];
A(2) = [];
Then
A = [1,3]

Add unknown number of elements to another cell array from a certain index on

I've data in the format of
a{1}(1,1)=1
a{1}(1,2)=3
a{1}(1,3)=0.5
a{1}(2,1)=1
a{1}(2,2)=5
a{1}(3,1)=2
a{1}(3,2)=7
...
Now I'd like to place item 1 & 2 of all rows in this cell into another cell array from an specific index on. How should I do this? for example to place column 1 & 2 of these unknown number of row in the cell array 'b' from index 5 on without repetition I used:
b{1}(1,(5:end + 1)) = unique(a{1}(:,(1:2)))
I'd like the output of cell array 'b{1}' from 5th elements becomes '1 2 3 5 7'.
However, it is false and gives the "Subscripted assignment dimension mismatch." error. I dont know where is the problem. Is my snippet right?
Any help is appreciated