cellstr(ch​ar(alarm_n​o(:).')) is not working properly; for same number it is showing empty and for same it was showing exact value.

조회 수: 1 (최근 30일)
Hi. I have two data sets; one is keys (A)and another one is variables to each keys (B) Here B is alarm_no whose length is 36*1. The reason I am using cellstr(char(x)) because for each A(keys) there are many values in B. In short I want data = [A(1) B(:,1)].
since dimensions are not matching; A is 1x1 now and B is let's say Px1. I am using cellstr which makes it 1x1 cell.
raw_data = cellstr(char(alarm_type(:).')); %alarm_type is B here and I am making it 1x1 cell to get desired
retrieved_data = double(cell2mat(raw_data)); %to check if original data is extracted or not
but unfortunately, I can't last element is empty. last element of original data is 9 which is also repeated in many other places but I am getting 9 back from those rows but not the last one.
original_data1 = [2 9 3 9 9 9 2 1 4 9 2 0 2 3 4 2 3 2 3 0 2 9 3 1 1 0 1 1 0 2 3 4 4 4 4 9]
retrieved_data = [2 9 3 9 9 9 2 1 4 9 2 0 2 3 4 2 3 2 3 0 2 9 3 1 1 0 1 1 0 2 3 4 4 4 4]
size(original_data1)= 36x1
size(retrieved_data)= 35x1
raw_data
' '
If anyone of you know why this is happening and how to solve this?
  댓글 수: 2
Adam Danz
Adam Danz 2018년 8월 6일
Please provide a minimal working example of the error you're getting. This should include a sample of your data that causes the problem, the code the causes the problem, and a clear description of what the problem is.
Ahsen Noor Subhopoto
Ahsen Noor Subhopoto 2018년 8월 6일
I have posted a picture which shows the data A B C D columns. A is unique let's say 35219, where as B C D are details related to A.
I am creating a data. in next iteration A is changed let's say 35242 and has different length. I want to store those A and related B C D of A after previous A has reached to end.
In short, as seen from the image I want to store 35242 (A) and its related details to be stored on data(36,:)
By replacing cellstr(char(C(:).')) with
D = cellstr(num2str(C)) %data is provided in the image (4th column). and D is just dummy variable
has solved the problem. But still i didn't get why cellstr(char(9)) is giving empty matrix in the raw_data(end) which causes 9 not to be retrieved in the retrieved_data(end).

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 8월 6일
cellstr trims trailing whitespace, and char(9) happens to be tab which is whitespace.
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 9월 19일
This is consistent with what I wrote: cellstr trims trailing whitespace, so only char(9) at the end are being thrown away.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by