Is there a function to convert column vector to matrix?

1 次查看(过去 30 天)
Hello everyone,
I am trying to create a map from below code. I have done logical indexing and therefore I have a column vector (668557x1). Kindly tell me how can I convert it to a matrix? Secondly, I am using geoshow to plot it. I just can't figure out whether problem lies in calling MOD_CER2 in geoshow or I should convert this column vector to matrix for plotting?
Any help is highly appreciated. Thank you.
MOD_CER(find(MOD_CER==-9999))=NaN;
cer = (MOD_CER).* 0.01;
index_liq = find(MOD_CP == 2);
MOD_CER2 = cer(index_liq);

采纳的回答

Jan
Jan 2021-5-29
编辑:Jan 2021-5-29
Hint: It is more efficient to omit the find() in:
MOD_CER(find(MOD_CER==-9999))=NaN;
% ^^^^
If you remove some arbitrary elements from a matrix, the result cannot be a matrix anymore. A matrix needs the same number of rows for each column, and columns for each row. Therefore after
index_liq = find(MOD_CP == 2);
MOD_CER2 = cer(index_liq); % 668557x1 double
it is not clear, how you want to convert it to a matrix.
Look at this small example:
x = [1, 2; 3, 4]
x(3) = [];
Now this vector x with 3 elements cannot be reshaped or whatever to be a matrix.
If you want to keep the matrix form, you need something like this:
MOD_CER2 = cer;
MOD_CER2(MOD_CP == 2) = NaN;
  2 个评论
IMC
IMC 2021-5-29
Thank you for your answer. I have made changes according to your suggestions and my map is displayed correctly. But there is one problem, in my data 2 and 3 represents Liquid and ice respectively and CER for former ranges from 4-30 and for later it ranges from 5-60. However, now if I use the below line values are not plotted for liquid (2) but infact the colorbar shows range from 5-60 (ice) and vice versa (using 3 (ice) will display colorbar for liquid (4-30). What is the reason for this?
MOD_CER2(MOD_CP == 2) = NaN;
Jan
Jan 2021-5-29
Sorry, I do not know what "data 2 and 3" are and what the meaning of "representing liquid and ice" means. For Matlab these are all numbers. In consequence it is not clear to me, what you are asking for.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by