How can I display all elements of an array in a single row?
이전 댓글 표시
hi, if I have an array, how I can display all elements in single row if I did not know the length of that row(i did not know the no. of columns) . where the size of rows is not equal
for ex.
A=CGCKCCD?QDCQC??FE?N?NBCBNM?AEZE*GAAWE?E-GQE?R?N??Y
G?GRHTHYH?H*HMHDHPH?HLHWGMHH?Y?AHCGYGAHEGBG?E?HRG*
HKHFIMI*GKITHPI-LRH?GRH?IBGSL?I?IXIFLAIYIZISHLHQIK
GRH?HKIGGPHPIHIELELILHLRIDQWLDLCAWGGGDLQHQ?L
GLQ?FEN-LLKBGAE??-?BNDNMLTELK?KXK?NHEADX?ACBAWMGK?
G?EWGMHFHWGRIVHPHSIAHZGNGKHBS?GCCZE*K*GY?EHHGVN?ND
GRHQHMGNISBSEYLQFHBPIBIWBTCKN?VLC?AWKAR-?ZCZC?P?A*
IVEWSHF?P?KWSPYEBWGVHQHIBYG??QLYQHAWPEPN
GMHFG?HAH?IFEBIMSPVFMFR?A*VXSAQRPMN?CFA?YNB?C?TFYB
G?XFGKGRBWIKXMI?XPHKH*XSHMIDGNXKGDNDQ?XCN?N-HNXQZM
THANKS
댓글 수: 4
Jan
2011년 10월 5일
How is the array represented in MATLAB? A cell string?
huda nawaf
2011년 10월 5일
Walter Roberson
2011년 10월 5일
A(3,:)
However, it is not possible to have a numeric array that has rows of different lengths.
Depending on the data type and the needs of your program, you might be able to use some particular flag value to indicate the logical end of data in the row. For example if the flag value was 255, then you could use
t = A(3,:);
L = find(t == 255,1) - 1;
if isempty(L); L = length(t); end
t(1:L)
huda nawaf
2011년 10월 5일
답변 (3개)
Walter Roberson
2011년 10월 5일
I am not sure what you are asking, but the below seems like a plausible answer:
a1 = cellstr(A);
fprintf('%s ', a1{:}); fprintf('\n');
Dr. Seis
2011년 10월 5일
If the string "A" also has end of line characters, then:
strf = strfind(A,sprintf('\n'));
B = {''};
if ~isempty(strf)
B = cellstr(A(1:strf(1)-1));
if numel(strf) > 1
for ii = 2 : numel(strf)
B(ii) = cellstr(A(strf(ii-1)+1:strf(ii)-1));
end
B(ii+1) = cellstr(A(strf(ii)+1:end));
else
B(2) = cellstr(A(strf(1)+1:end));
end
else
B = cellstr(A);
end
Where "B" is now a cell array. You can access/convert any row back to a string by, for example:
row_string = char(B(some_row));
댓글 수: 3
Dr. Seis
2011년 10월 5일
If your string "A" is created more like:
A = ['abc '; 'defg'; 'hi ']
A =
abc
defg
hi
then it is trivial to extract a row, just type:
deblank(A(some_row,:))
Walter Roberson
2011년 10월 5일
Of if you have done
t = cellstr(A);
then just t{some_row}
Dr. Seis
2011년 10월 5일
Ah, cool. I don't have to do this anymore:
fprintf('%s',char(t(some_row)));
Robert
2011년 10월 5일
0 개 추천
Arrays cannot have different numbers of columns in each row. Maybe you're dealing with a cell array, in which case you'd just type: A{3} For an array you'd type A(3,:).
댓글 수: 3
Walter Roberson
2011년 10월 5일
The posted example is characters and every line of characters is exactly the same size, with blanks to fill out to the end of the row. That is typical for character arrays: each row does actually have the same length, but it is a matter of individual program interpretation as to whether the trailing blanks in rows are meaningful or not.
huda nawaf
2011년 10월 5일
Dr. Seis
2011년 10월 5일
Search for "cellstr" within the Matlab Help Navigator.
카테고리
도움말 센터 및 File Exchange에서 Resampling Techniques에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!